CFx SDK Documentation  2023 SP0
FMDrawBody.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2015, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2015 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef __FMMDL_DRAW_BODY_H__
25 #define __FMMDL_DRAW_BODY_H__
26 
27 #include <Modeler/FMMdlBody.h>
28 #include <Gi/GiGeometry.h>
29 #include <Gi/GiCommonDraw.h>
30 #include <Modeler/FMMdlIterators.h>
31 #include "Modeler/FMMdlSurface.h"
32 #include <FMGeometry.h>
33 #include <Int32Array.h>
34 
35 namespace FacetModeler {
36 
37 inline void
38 DrawBodySurface( OdGiCommonDraw* pDraw, const Body& rBody, const Surface* pSurface, const OdGeVector3d* pViewDir );
39 
42 inline void
43 DrawBody( OdGiCommonDraw* pDraw, const Body& rBody, const OdGeVector3d* pViewDir = 0 ) {
44  if ( !rBody.isNull() ) {
46  VertexIterator vi( &rBody );
47  while( !vi.done() ) {
48  vertexTagsSaved.append( vi.get()->tag() );
49  vi.get()->setTag( 0 );
50  vi.next();
51  }
52 
53  DrawBodySurface( pDraw, rBody, 0, pViewDir );
54  Surface* pSurf = rBody.surfaceList();
55 
56  OdUInt32 i;
57  for( i = 0; i<rBody.surfaceCount(); ++i ) {
58  ODA_ASSERT( pSurf!=0 );
59  DrawBodySurface( pDraw, rBody, pSurf, pViewDir );
60  pSurf = pSurf->next();
61  }
62 
63  i = 0;
64  vi = VertexIterator( &rBody );
65  while( !vi.done() ) {
66  vi.get()->setTag( vertexTagsSaved[i++] );
67  vi.next();
68  }
69  }
70 }
71 
72 inline void
73 DrawBodySurface( OdGiCommonDraw* pDraw, const Body& rBody, const Surface* pSurface, const OdGeVector3d* pViewDir ) {
74  OdUInt32 iVCount = rBody.vertexCount();
75  OdUInt32 iECount = rBody.countEdges();
76  OdUInt32 iFCount = rBody.faceCount();
77 
78  OdGeVector3dArray normals;
79  OdGePoint3dArray aVertices;
80  aVertices.reserve( iVCount );
81 
82  OdGiEdgeData cEdgeData;
83  OdGiFaceData cFaceData;
84  OdGiVertexData cVertexData;
85 
86  OdUInt8Array vEdgeVisibilities;
87  OdUInt8Array vFaceVisibilities;
88  normals.reserve( aVertices.size() );
89  vEdgeVisibilities.reserve( iECount );
90  vFaceVisibilities.reserve( iFCount );
91 
92  OdInt32Array vFD;
93  vFD.reserve( iECount + iFCount * 2 );
94 
95  OdGeVector3dArray vNormals;
96  vNormals.reserve( iFCount );
97 
98  bool bFaceVis = false;
99  bool bEdgeVis = false;
100  FaceIterator itF( &rBody );
101  OdInt16 color = pDraw->subEntityTraits().color();
102  pDraw->subEntityTraits().setColor( 7 );
103 
104  while( !itF.done() ) {
105  if( itF.get()->surface()!=pSurface ) {
106  itF.next();
107  continue;
108  }
109  vNormals.push_back( itF.get()->normal() );
110 
112  if ( itF.get()->isFlagOn( VFF ) )
113  eFVis = kOdGiInvisible;
114  if ( itF.get()->orientation() == efoDiscard )
115  eFVis = kOdGiInvisible;
116 
117  vFaceVisibilities.push_back( (OdUInt8)eFVis );
118  if( eFVis!=kOdGiVisible ) {
119  bFaceVis = true;
120  }
121 
122  OdUInt32 i, iSize = itF.get()->loopCount();
123  for ( i = 0; i < iSize; i++ ) {
124  vFD.push_back( 0 ); // reserve space for size
125  OdInt32 nFaceStart = vFD.size();
126 
127  Edge* pE = itF.get()->edge( i );
128  Edge* pS = pE;
129  do {
130  Vertex* pVertex = pE->vertex();
131  OdInt32 vertexId = (OdInt32)pVertex->tag();
132  // use 1-based indecies to have zero as "unused" flag
133  if( vertexId > 0 ) {
134  --vertexId;
135  }
136  else {
137  vertexId = aVertices.size();
138  aVertices.push_back( pVertex->point() );
139  pVertex->setTag( vertexId+1 );
140  if( pSurface ) {
141  pVertex->normal( *itF.get(), *normals.append() );
142 
143  // draw vertex normals for debugging
144  //OdGePoint3d pts[] = { pVertex->point(), pVertex->point() + normals.last() * 1.5 };
145  //pDraw->geometry().polyline( 2, pts );
146  }
147  }
148 
149  vFD.push_back( vertexId );
150 
152  if ( pE->isFlagOn( VEF ) ) {
153  eVis = kOdGiInvisible;
154  }
155  else if ( pE->isFlagOn( AEF ) ) {
156  if( pViewDir ) {
157  Edge* pPair = pE->pair();
158  if ( pPair ) {
159  OdGeVector3d vNrm1 = pE->face()->normal();
160  OdGeVector3d vNrm2 = pPair->face()->normal();
161 
162  if ( ((pViewDir->dotProduct( vNrm1 ) > 0) == (pViewDir->dotProduct( vNrm2 ) > 0)) ) {
163  eVis = kOdGiInvisible;
164  }
165  else {
166  eVis = kOdGiVisible;
167  }
168  }
169  }
170  else {
171  eVis = kOdGiSilhouette;
172  }
173  }
174 
175  vEdgeVisibilities.push_back( (OdUInt8)eVis );
176  if( eVis!=kOdGiVisible ) {
177  bEdgeVis = true;
178  }
179 
180  pE = pE->next();
181  }
182  while( pE != pS );
183 
184  // set face size or hole -size
185  vFD[ nFaceStart-1 ] = ( i==0 ? vFD.size() - nFaceStart : nFaceStart - vFD.size() );
186  }
187 
188  itF.next();
189  }
190  pDraw->subEntityTraits().setColor( color );
191 
192  if( vFD.size() ) {
193  if( bEdgeVis )
194  cEdgeData.setVisibility( vEdgeVisibilities.getPtr() );
195  if( bFaceVis )
196  cFaceData.setVisibility( vFaceVisibilities.getPtr() );
197  cVertexData.setNormals( normals.getPtr() );
198  cFaceData.setNormals( vNormals.getPtr() );
199 
200  pDraw->rawGeometry().shell(
201  aVertices.size(),
202  aVertices.getPtr(),
203  vFD.size(),
204  vFD.getPtr(),
205  bEdgeVis ? &cEdgeData : 0,
206  &cFaceData,
207  normals.size() ? &cVertexData : 0
208  );
209  }
210 }
211 }
212 #endif //#ifndef __FMMDL_DRAW_BODY_H__
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
OdGiVisibility
Definition: Gi.h:46
@ kOdGiSilhouette
Definition: Gi.h:49
@ kOdGiInvisible
Definition: Gi.h:47
@ kOdGiVisible
Definition: Gi.h:48
unsigned int OdUInt32
short OdInt16
int OdInt32
unsigned char OdUInt8
Surface * surfaceList() const
OdUInt32 surfaceCount() const
OdUInt32 faceCount() const
OdUInt32 vertexCount() const
OdUInt32 countEdges() const
bool isNull() const
FacetModeler::Vertex * vertex() const
Edge * next() const
FacetModeler::Face * face() const
Edge * pair() const
void setTag(FacetModeler::AecTagType nTag)
Definition: FMMdlEntity.h:136
FacetModeler::AecTagType tag() const
Definition: FMMdlEntity.h:132
bool isFlagOn(OdUInt32 iFlag) const
Definition: FMMdlEntity.h:124
OdGeVector3d normal() const
FaceOrientation orientation() const
Surface * surface() const
Definition: FMMdlFace.h:171
OdUInt32 loopCount() const
Edge * edge(OdUInt32 nLoop=0) const
Surface * next() const
void normal(const Face &atF, OdGeVector3d &normal) const
const OdGePoint3d & point() const
size_type size() const
Definition: OdArray.h:893
void push_back(const T &value)
Definition: OdArray.h:987
const T * getPtr() const
Definition: OdArray.h:1102
void reserve(size_type reserveLength)
Definition: OdArray.h:920
size_type append(const T &value)
Definition: OdArray.h:1215
double dotProduct(const OdGeVector3d &vect) const
Definition: GeVector3d.h:487
virtual OdGiGeometry & rawGeometry() const =0
virtual OdGiSubEntityTraits & subEntityTraits() const =0
void setVisibility(const OdUInt8 *visibilities)
Definition: GiGeometry.h:167
void setNormals(const OdGeVector3d *normals)
Definition: GiGeometry.h:333
void setVisibility(const OdUInt8 *visibilities)
Definition: GiGeometry.h:354
virtual void shell(OdInt32 numVertices, const OdGePoint3d *vertexList, OdInt32 faceListSize, const OdInt32 *faceList, const OdGiEdgeData *pEdgeData=0, const OdGiFaceData *pFaceData=0, const OdGiVertexData *pVertexData=0)=0
virtual OdUInt16 color() const =0
virtual void setColor(OdUInt16 color)=0
void setNormals(const OdGeVector3d *normals)
Definition: GiGeometry.h:573
void DrawBodySurface(OdGiCommonDraw *pDraw, const Body &rBody, const Surface *pSurface, const OdGeVector3d *pViewDir)
Definition: FMDrawBody.h:73
const OdUInt32 VEF
Definition: FMMdlEdge.h:37
const OdUInt32 VFF
Definition: FMMdlFace.h:36
const OdUInt32 AEF
Definition: FMMdlEdge.h:36
void DrawBody(OdGiCommonDraw *pDraw, const Body &rBody, const OdGeVector3d *pViewDir=0)
Definition: FMDrawBody.h:43