How to retrieve the color of a point (in a BRep model)

How to retrieve the color of a point (in a BRep model)

1. Get the ModelData_BRepRepresentation of a part;
2. Get a list of all the Bodies that belong to this Part: ModelData_BodyList aBodyList = theBRep.Get();
3. Use Appearance(aBody) method of the ModelData_BRepRepresentation object to retrieve appearance of the Body;
4. Use ToColor method of the ModelData_Appearance object to get the color.

Here's an example of code for a viewer:
  1. class PartBRepVisitor : ModelData_Model.VoidElementVisitor
  2. {
  3.     public PartBRepVisitor()
  4.     {
  5.     }

  6.     public override void Apply(ModelData_Part thePart)
  7.     {
  8.         ModelData_BRepRepresentation aBRep = thePart.BRepRepresentation();
  9.         if (aBRep != null)
  10.         {
  11.             ExploreBRep(aBRep);
  12.         }
  13.     }

  14.     private void ExploreBRep(ModelData_BRepRepresentation theBRep)
  15.     {
  16.         ModelData_BodyList aBodyList = theBRep.Get();
  17.         for (uint i = 0; i < aBodyList.Size(); ++i)
  18.         {
  19.             ModelData_Body aBody = aBodyList.Access(i);
  20.             if (aBody.BodyType() == ModelData_BodyType.ModelData_BT_Acorn)
  21.             {
  22.                 ModelData_Appearance anApperance = theBRep.Appearance(aBody);
  23.                 ModelData_Color aColor = new ModelData_Color();
  24.                 anApperance.ToColor(aColor);
  25.                 Console.WriteLine(aColor.R());
  26.                 Console.WriteLine(aColor.G());
  27.                 Console.WriteLine(aColor.B());
  28.             }
  29.         }
  30.     }
  31. }

    • Related Articles

    • BRep Simplification

      B-Rep simplification is tool of Advanced Geometry Processing add-on that simplifies the geometry of B-Rep and mixed (B-Rep and polygonal) models. Features it can affect include holes, small bodies, internal non-visible faces and bodies, and also ...
    • How to change a selection color

      Web Toolkit version 1.x There is an opportunity to change the selection color. In viewer.js you need to add a ModelData_ColorObject in ModelPrs_DisplayParams and add ModelPrs_DisplayParams into ModelPrs_DisplayerApplier This a small example how to do ...
    • Why can't my model be processed?

      The problem may stem either from CAD Exchanger or from the file you want to convert, but we won't be able to figure it out without reproducing the difficulties you're having, so please share your model for us to look into via this contact form. It ...
    • My model rotated after conversion. Why it happens?

      Different softwares use different axis orientations. That is quite a common thing to occur when a model moves between various 3d software packages. CAD Exchanger uses a right-handed coordinate system. CAD Exchanger Lab offers the axis orientation ...
    • Can I edit my model in CAD Exchanger Lab?

      CAD Exchanger Lab is only intended to be a viewer and converter. Although transformation and colors of the model’s elements can be changed with its help, editing their geometry will require the CAD Exchanger SDK.