2 // File : GEOM_AssemblyBuilder.cxx
3 // Created : Wed Feb 20 17:24:59 2002
4 // Author : Christophe ATTANASIO
7 // Copyright : Open CASCADE 2002
11 \class GEOM_AssemblyBuilder GEOM_AssemblyBuilder.h
15 #include "GEOM_AssemblyBuilder.h"
16 #include "GEOM_Actor.h"
17 #include "utilities.h"
19 // Open CASCADE Includes
20 #include <TopExp_Explorer.hxx>
21 #include <Bnd_Box.hxx>
22 #include <BRepMesh_IncrementalMesh.hxx>
23 #include <Poly_Triangulation.hxx>
24 #include <BRepBndLib.hxx>
25 #include <BRep_Tool.hxx>
26 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
28 #include <TopTools_ListOfShape.hxx>
32 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
33 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
39 void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp,
40 vtkProperty* FaceProp,
41 vtkProperty* EdgeFProp,
42 vtkProperty* EdgeSProp,
43 vtkProperty* EdgeIProp,
44 vtkProperty* VertexProp,
45 vtkProperty* IsoPVProp,
46 vtkProperty* EdgePVProp,
47 vtkProperty* VertexPVProp)
49 // Shading like default OCC material
50 FaceProp->SetRepresentationToSurface();
51 FaceProp->SetInterpolation(1);
52 FaceProp->SetAmbient(1.0);
53 FaceProp->SetDiffuse(1.0);
54 FaceProp->SetSpecular(0.4);
55 FaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
56 FaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
57 FaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
60 IsoProp->SetRepresentationToWireframe();
61 IsoProp->SetAmbientColor(0.5, 0.5, 0.5);
62 IsoProp->SetDiffuseColor(0.5, 0.5, 0.5);
63 IsoProp->SetSpecularColor(0.5, 0.5, 0.5);
66 IsoPVProp->SetRepresentationToWireframe();
67 IsoPVProp->SetAmbientColor(0, 1, 1);
68 IsoPVProp->SetDiffuseColor(0, 1, 1);
69 IsoPVProp->SetSpecularColor(0, 1, 1);
71 // Wireframe for shared edge
72 EdgeSProp->SetRepresentationToWireframe();
73 EdgeSProp->SetAmbientColor(1, 1, 0);
74 EdgeSProp->SetDiffuseColor(1, 1, 0);
75 EdgeSProp->SetSpecularColor(1, 1, 0);
77 // Wireframe for free edge
78 EdgeFProp->SetRepresentationToWireframe();
79 EdgeFProp->SetAmbientColor(0, 1, 0);
80 EdgeFProp->SetDiffuseColor(0, 1, 0);
81 EdgeFProp->SetSpecularColor(0, 1, 0);
83 // Wireframe for isolated edge
84 EdgeIProp->SetRepresentationToWireframe();
85 EdgeIProp->SetAmbientColor(1, 0, 0);
86 EdgeIProp->SetDiffuseColor(1, 0, 0);
87 EdgeIProp->SetSpecularColor(1, 0, 0);
89 // Wireframe for Preview edge
90 EdgePVProp->SetRepresentationToWireframe();
91 EdgePVProp->SetAmbientColor(0, 1, 1);
92 EdgePVProp->SetDiffuseColor(0, 1, 1);
93 EdgePVProp->SetSpecularColor(0, 1, 1);
95 // Wireframe for vertex
96 VertexProp->SetRepresentationToWireframe();
97 VertexProp->SetAmbientColor(1, 1, 0);
98 VertexProp->SetDiffuseColor(1, 1, 0);
99 VertexProp->SetSpecularColor(1, 1, 0);
101 // Wireframe for vertex
102 VertexPVProp->SetRepresentationToWireframe();
103 VertexPVProp->SetAmbientColor(0, 1, 1);
104 VertexPVProp->SetDiffuseColor(0, 1, 1);
105 VertexPVProp->SetSpecularColor(0, 1, 1);
109 void GEOM_AssemblyBuilder::MeshShape(const TopoDS_Shape myShape,
110 Standard_Real deflection,
111 Standard_Boolean forced)
113 // Mesh the shape if necessary
114 Standard_Boolean alreadymesh = Standard_True;
116 TopLoc_Location aLoc;
118 for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
119 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
120 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
121 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
124 if(!alreadymesh || forced) {
126 // Compute default deflection
128 BRepBndLib::Add(myShape, B);
129 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
130 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
131 deflection = MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.001 *4;
133 BRepMesh_IncrementalMesh MESH(myShape,deflection);
139 vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShape,
140 Standard_Real deflection,
141 Standard_Integer mode,
142 Standard_Boolean forced) {
144 vtkActorCollection* AISActors = vtkActorCollection::New();
146 // Create graphics properties
148 vtkProperty* IsoProp = vtkProperty::New();
149 vtkProperty* FaceProp = vtkProperty::New();
150 vtkProperty* EdgeFProp = vtkProperty::New();
151 vtkProperty* EdgeSProp = vtkProperty::New();
152 vtkProperty* EdgeIProp = vtkProperty::New();
153 vtkProperty* VertexProp = vtkProperty::New();
155 vtkProperty* IsoPVProp = vtkProperty::New();
156 vtkProperty* EdgePVProp = vtkProperty::New();
157 vtkProperty* VertexPVProp = vtkProperty::New();
159 InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp);
161 MeshShape(myShape,deflection,forced);
163 if ( myShape.ShapeType() <= 4 ) {
166 // look if edges are free or shared
167 TopTools_IndexedDataMapOfShapeListOfShape edgemap;
168 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,edgemap);
172 for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
174 GEOM_Actor* FaceActor = GEOM_Actor::New();
175 FaceActor->SetShadingProperty(FaceProp);
176 FaceActor->SetWireframeProperty(IsoProp);
178 FaceActor->SetPreviewProperty(IsoPVProp);
180 FaceActor->setInputShape(ex.Current(),deflection,mode);
182 AISActors->AddItem(FaceActor);
185 for (ex2.Init(ex.Current(), TopAbs_EDGE); ex2.More(); ex2.Next()) {
186 const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current());
188 if (BRep_Tool::Degenerated(aEdge)) {
192 // compute the number of faces
193 Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent();
194 GEOM_Actor* EdgeActor = GEOM_Actor::New();
195 EdgeActor->SubShapeOn();
196 EdgeActor->setInputShape(ex2.Current(),deflection,mode);
199 case 0 : // isolated edge
201 EdgeActor->SetShadingProperty(EdgeIProp);
202 EdgeActor->SetWireframeProperty(EdgeIProp);
206 case 1 :// edge in only one face
208 EdgeActor->SetShadingProperty(EdgeFProp);
209 EdgeActor->SetWireframeProperty(EdgeFProp);
213 default : // edge shared by at least two faces
215 EdgeActor->SetShadingProperty(EdgeSProp);
216 EdgeActor->SetWireframeProperty(EdgeSProp);
219 EdgeActor->SetPreviewProperty(EdgePVProp);
220 AISActors->AddItem(EdgeActor);
223 } else if ( myShape.ShapeType() == TopAbs_WIRE ) { // WIRE Actor
225 for (ex.Init(myShape, TopAbs_EDGE); ex.More(); ex.Next()) {
226 const TopoDS_Edge& aEdge = TopoDS::Edge(ex.Current());
228 if (BRep_Tool::Degenerated(aEdge)) {
232 GEOM_Actor* EdgeActor = GEOM_Actor::New();
233 EdgeActor->setInputShape(ex.Current(),deflection,mode);
234 EdgeActor->SetShadingProperty(EdgeIProp);
235 EdgeActor->SetWireframeProperty(EdgeIProp);
236 EdgeActor->SetPreviewProperty(EdgePVProp);
238 AISActors->AddItem(EdgeActor);
240 } else if ( myShape.ShapeType() == TopAbs_EDGE ) { // EDGE Actor
241 GEOM_Actor* EdgeActor = GEOM_Actor::New();
242 EdgeActor->setInputShape(myShape,deflection,mode);
243 EdgeActor->SetShadingProperty(EdgeIProp);
244 EdgeActor->SetWireframeProperty(EdgeIProp);
245 EdgeActor->SetPreviewProperty(EdgePVProp);
247 AISActors->AddItem(EdgeActor);
248 } else if ( myShape.ShapeType() == TopAbs_VERTEX ) { // VERTEX Actor
249 GEOM_Actor* VertexActor = GEOM_Actor::New();
250 VertexActor->setInputShape(myShape,deflection,mode);
251 VertexActor->SetShadingProperty(VertexProp);
252 VertexActor->SetWireframeProperty(VertexProp);
253 VertexActor->SetPreviewProperty(VertexPVProp);
255 AISActors->AddItem(VertexActor);
265 //-------------------------------------------------------------
267 //-------------------------------------------------------------
268 vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape,
269 Standard_Real deflection,
270 Standard_Integer mode,
271 Standard_Boolean forced)
273 // Create a new vtkAssembly
275 vtkAssembly* myVTKShape = vtkAssembly::New();
278 // Create graphics properties
280 vtkProperty* IsoProp = vtkProperty::New();
281 vtkProperty* FaceProp = vtkProperty::New();
282 vtkProperty* EdgeFProp = vtkProperty::New();
283 vtkProperty* EdgeSProp = vtkProperty::New();
284 vtkProperty* EdgeIProp = vtkProperty::New();
285 vtkProperty* VertexProp = vtkProperty::New();
286 vtkProperty* EdgePVProp = vtkProperty::New();
287 vtkProperty* VertexPVProp = vtkProperty::New();
288 vtkProperty* IsoPVProp = vtkProperty::New();
290 InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp);
292 MeshShape(myShape,deflection,forced);
297 // look if edges are free or shared
298 TopTools_IndexedDataMapOfShapeListOfShape edgemap;
299 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,edgemap);
303 for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
304 //const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
306 GEOM_Actor* FaceActor = GEOM_Actor::New();
307 FaceActor->SetShadingProperty(FaceProp);
308 FaceActor->SetWireframeProperty(IsoProp);
310 vtkAssembly* myFaceAssembly = vtkAssembly::New();
313 FaceActor->setInputShape(ex.Current(),deflection,mode);
314 myFaceAssembly->AddPart(FaceActor);
317 for (ex2.Init(ex.Current(), TopAbs_EDGE); ex2.More(); ex2.Next()) {
318 const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current());
320 if (BRep_Tool::Degenerated(aEdge)) {
325 // compute the number of faces
326 Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent();
327 GEOM_Actor* EdgeActor = GEOM_Actor::New();
330 case 0 : // isolated edge
332 EdgeActor->SetShadingProperty(EdgeIProp);
333 EdgeActor->SetWireframeProperty(EdgeIProp);
337 case 1 :// edge in only one face
339 EdgeActor->SetShadingProperty(EdgeFProp);
340 EdgeActor->SetWireframeProperty(EdgeFProp);
344 default : // edge shared by at least two faces
346 EdgeActor->SetShadingProperty(EdgeSProp);
347 EdgeActor->SetWireframeProperty(EdgeSProp);
351 EdgeActor->setInputShape(ex2.Current(),deflection,mode);
352 myFaceAssembly->AddPart(EdgeActor);
354 myVTKShape->AddPart(myFaceAssembly);
361 //-------------------------------------------------------------
362 // CHANGE SPECIFIC DISPLAY MODE
363 //-------------------------------------------------------------
364 void GEOM_AssemblyBuilder::SwitchDisplayMode(vtkAssembly* aOCCAssembly)
368 void GEOM_AssemblyBuilder::SwitchDisplayMode(vtkActorCollection* aOCCAssembly)
372 //-------------------------------------------------------------
374 //-------------------------------------------------------------
376 void GEOM_AssemblyBuilder::DisplayErase(vtkAssembly* mySALOMEAssembly)
381 void GEOM_AssemblyBuilder::DisplayErase(vtkActorCollection* mySALOMEActors)