KiCad PCB EDA Suite
SGFACESET Class Reference

Define an indexed face set for a scenegraph. More...

#include <sg_faceset.h>

Inheritance diagram for SGFACESET:
SGNODE

Public Member Functions

 SGFACESET (SGNODE *aParent)
 
virtual ~SGFACESET ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set the parent SGNODE of this object. More...
 
SGNODEFindNode (const char *aNodeName, const SGNODE *aCaller) override
 Search the tree of linked nodes and return a reference to the first node found with the given name. More...
 
bool AddRefNode (SGNODE *aNode) override
 
bool AddChildNode (SGNODE *aNode) override
 
bool CalcNormals (SGNODE **aPtr)
 
void ReNameNodes (void) override
 Rename a node and all its child nodes in preparation for write operations. More...
 
bool WriteVRML (std::ostream &aFile, bool aReuseFlag) override
 Writes this node's data to a VRML file. More...
 
bool WriteCache (std::ostream &aFile, SGNODE *parentNode) override
 Write this node's data to a binary cache file. More...
 
bool ReadCache (std::istream &aFile, SGNODE *parentNode) override
 Reads binary format data from a cache file. More...
 
void GatherCoordIndices (std::vector< int > &aIndexList)
 Add all internal coordinate indices to the given list in preparation for a normals calculation. More...
 
void unlinkChildNode (const SGNODE *aNode) override
 Remove references to an owned child. More...
 
void unlinkRefNode (const SGNODE *aNode) override
 Remove pointers to a referenced node. More...
 
bool validate (void)
 
S3D::SGTYPES GetNodeType (void) const noexcept
 Return the type of this node instance. More...
 
SGNODEGetParent (void) const noexcept
 Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
bool SwapParent (SGNODE *aNewParent)
 Swap the ownership with the given parent. More...
 
const char * GetName (void)
 
void SetName (const char *aName)
 
const char * GetNodeTypeName (S3D::SGTYPES aNodeType) const noexcept
 
void AssociateWrapper (SGNODE **aWrapperRef) noexcept
 Associate this object with a handle to itself. More...
 
void DisassociateWrapper (SGNODE **aWrapperRef) noexcept
 Remove the association between an IFSG* wrapper object and this object. More...
 
void ResetNodeIndex (void) noexcept
 Reset the global SG* node indices in preparation for write operations. More...
 
void addNodeRef (SGNODE *aNode)
 Add a pointer to a node which references this node, but does not own. More...
 
void delNodeRef (const SGNODE *aNode)
 Remove a pointer to a node which references this node, but does not own. More...
 
bool isWritten (void) noexcept
 Return true if the object had already been written to a cache file or VRML file. More...
 

Public Attributes

SGCOLORSm_Colors
 
SGCOORDSm_Coords
 
SGCOORDINDEXm_CoordIndices
 
SGNORMALSm_Normals
 
SGCOLORSm_RColors
 
SGCOORDSm_RCoords
 
SGNORMALSm_RNormals
 

Protected Attributes

std::list< SGNODE * > m_BackPointers
 nodes which hold a reference to this. More...
 
SGNODEm_Parent
 Pointer to parent node; may be NULL for top level transform. More...
 
S3D::SGTYPES m_SGtype
 Type of Scene Graph node. More...
 
std::string m_Name
 name to use for referencing the entity by name. More...
 
bool m_written
 Set to true when the object has been written after a ReNameNodes(). More...
 

Private Member Functions

void unlinkNode (const SGNODE *aNode, bool isChild)
 
bool addNode (SGNODE *aNode, bool isChild)
 

Private Attributes

bool valid
 
bool validated
 
SGNODE ** m_Association
 Handle to the instance held by a wrapper. More...
 

Detailed Description

Define an indexed face set for a scenegraph.

Definition at line 46 of file sg_faceset.h.

Constructor & Destructor Documentation

◆ SGFACESET()

SGFACESET::SGFACESET ( SGNODE aParent)

Definition at line 38 of file sg_faceset.cpp.

38 : SGNODE( aParent )
39{
41 m_Colors = nullptr;
42 m_Coords = nullptr;
43 m_CoordIndices = nullptr;
44 m_Normals = nullptr;
45 m_RColors = nullptr;
46 m_RCoords = nullptr;
47 m_RNormals = nullptr;
48 valid = false;
49 validated = false;
50
51 if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
52 {
53 m_Parent = nullptr;
54
55 wxLogTrace( MASK_3D_SG,
56 wxT( "%s:%s:%d * [BUG] inappropriate parent to SGFACESET (type %s)" ),
57 __FILE__, __FUNCTION__, __LINE__,
58 aParent->GetNodeType() );
59 }
60 else if( nullptr != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
61 {
62 m_Parent->AddChildNode( this );
63 }
64}
bool validated
Definition: sg_faceset.h:91
SGCOORDS * m_RCoords
Definition: sg_faceset.h:86
SGCOORDINDEX * m_CoordIndices
Definition: sg_faceset.h:81
SGCOORDS * m_Coords
Definition: sg_faceset.h:80
SGNORMALS * m_Normals
Definition: sg_faceset.h:82
SGCOLORS * m_RColors
Definition: sg_faceset.h:85
SGNORMALS * m_RNormals
Definition: sg_faceset.h:87
bool valid
Definition: sg_faceset.h:90
SGCOLORS * m_Colors
Definition: sg_faceset.h:79
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104
virtual bool AddChildNode(SGNODE *aNode)=0
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
@ SGTYPE_SHAPE
Definition: sg_types.h:44
@ SGTYPE_FACESET
Definition: sg_types.h:40

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), m_Colors, m_CoordIndices, m_Coords, m_Normals, SGNODE::m_Parent, m_RColors, m_RCoords, m_RNormals, SGNODE::m_SGtype, S3D::SGTYPE_FACESET, S3D::SGTYPE_SHAPE, valid, and validated.

◆ ~SGFACESET()

SGFACESET::~SGFACESET ( )
virtual

Definition at line 67 of file sg_faceset.cpp.

68{
69 // drop references
70 if( m_RColors )
71 {
72 m_RColors->delNodeRef( this );
73 m_RColors = nullptr;
74 }
75
76 if( m_RCoords )
77 {
78 m_RCoords->delNodeRef( this );
79 m_RCoords = nullptr;
80 }
81
82 if( m_RNormals )
83 {
84 m_RNormals->delNodeRef( this );
85 m_RNormals = nullptr;
86 }
87
88 // delete owned objects
89 if( m_Colors )
90 {
91 m_Colors->SetParent( nullptr, false );
92 delete m_Colors;
93 m_Colors = nullptr;
94 }
95
96 if( m_Coords )
97 {
98 m_Coords->SetParent( nullptr, false );
99 delete m_Coords;
100 m_Coords = nullptr;
101 }
102
103 if( m_Normals )
104 {
105 m_Normals->SetParent( nullptr, false );
106 delete m_Normals;
107 m_Normals = nullptr;
108 }
109
110 if( m_CoordIndices )
111 {
112 m_CoordIndices->SetParent( nullptr, false );
113 delete m_CoordIndices;
114 m_CoordIndices = nullptr;
115 }
116}
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_colors.cpp:58
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_coords.cpp:60
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_index.cpp:52
void delNodeRef(const SGNODE *aNode)
Remove a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:185
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_normals.cpp:59

References SGNODE::delNodeRef(), m_Colors, m_CoordIndices, m_Coords, m_Normals, m_RColors, m_RCoords, m_RNormals, SGCOLORS::SetParent(), SGCOORDS::SetParent(), SGINDEX::SetParent(), and SGNORMALS::SetParent().

Member Function Documentation

◆ AddChildNode()

bool SGFACESET::AddChildNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 407 of file sg_faceset.cpp.

408{
409 return addNode( aNode, true );
410}
bool addNode(SGNODE *aNode, bool isChild)
Definition: sg_faceset.cpp:275

References addNode().

◆ addNode()

bool SGFACESET::addNode ( SGNODE aNode,
bool  isChild 
)
private

Definition at line 275 of file sg_faceset.cpp.

276{
277 wxCHECK( aNode, false );
278
279 valid = false;
280 validated = false;
281
282 if( S3D::SGTYPE_COLORS == aNode->GetNodeType() )
283 {
284 if( m_Colors || m_RColors )
285 {
286 if( aNode != m_Colors && aNode != m_RColors )
287 {
288 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Colors nodes" ),
289 __FILE__, __FUNCTION__, __LINE__ );
290
291 return false;
292 }
293
294 return true;
295 }
296
297 if( isChild )
298 {
299 m_Colors = (SGCOLORS*)aNode;
300 m_Colors->SetParent( this );
301 }
302 else
303 {
304 m_RColors = (SGCOLORS*)aNode;
305 m_RColors->addNodeRef( this );
306 }
307
308 return true;
309 }
310
311 if( S3D::SGTYPE_COORDS == aNode->GetNodeType() )
312 {
313 if( m_Coords || m_RCoords )
314 {
315 if( aNode != m_Coords && aNode != m_RCoords )
316 {
317 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Colors nodes" ),
318 __FILE__, __FUNCTION__, __LINE__ );
319
320 return false;
321 }
322
323 return true;
324 }
325
326 if( isChild )
327 {
328 m_Coords = (SGCOORDS*)aNode;
329 m_Coords->SetParent( this );
330 }
331 else
332 {
333 m_RCoords = (SGCOORDS*)aNode;
334 m_RCoords->addNodeRef( this );
335 }
336
337 return true;
338 }
339
340 if( S3D::SGTYPE_NORMALS == aNode->GetNodeType() )
341 {
342 if( m_Normals || m_RNormals )
343 {
344 if( aNode != m_Normals && aNode != m_RNormals )
345 {
346 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] assigning multiple Normals nodes" ),
347 __FILE__, __FUNCTION__, __LINE__ );
348
349 return false;
350 }
351
352 return true;
353 }
354
355 if( isChild )
356 {
357 m_Normals = (SGNORMALS*)aNode;
358 m_Normals->SetParent( this );
359 }
360 else
361 {
362 m_RNormals = (SGNORMALS*)aNode;
363 m_RNormals->addNodeRef( this );
364 }
365
366 return true;
367 }
368
369 if( S3D::SGTYPE_COORDINDEX == aNode->GetNodeType() )
370 {
371 if( m_CoordIndices )
372 {
373 if( aNode != m_CoordIndices )
374 {
375 wxLogTrace( MASK_3D_SG,
376 wxT( "%s:%s:%d * [BUG] assigning multiple CoordIndex nodes" ),
377 __FILE__, __FUNCTION__, __LINE__ );
378
379 return false;
380 }
381
382 return true;
383 }
384
386 m_CoordIndices->SetParent( this );
387
388 return true;
389 }
390
391 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] object type '%s' is not a valid type for "
392 "this object '%d'" ),
393 __FILE__, __FUNCTION__, __LINE__,
394 aNode->GetName(),
395 aNode->GetNodeType() );
396
397 return false;
398}
Define an RGB color set for a scenegraph object.
Definition: sg_colors.h:39
An object to maintain a coordinate index list.
Definition: sg_coordindex.h:43
Define a vertex coordinate set for a scenegraph object.
Definition: sg_coords.h:41
const char * GetName(void)
Definition: sg_node.cpp:146
void addNodeRef(SGNODE *aNode)
Add a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:170
Define a set of vertex normals for a scene graph object.
Definition: sg_normals.h:39
@ SGTYPE_COLORS
Definition: sg_types.h:38
@ SGTYPE_NORMALS
Definition: sg_types.h:43
@ SGTYPE_COORDS
Definition: sg_types.h:41
@ SGTYPE_COORDINDEX
Definition: sg_types.h:42

References SGNODE::addNodeRef(), SGNODE::GetName(), SGNODE::GetNodeType(), m_Colors, m_CoordIndices, m_Coords, m_Normals, m_RColors, m_RCoords, m_RNormals, SGCOLORS::SetParent(), SGCOORDS::SetParent(), SGINDEX::SetParent(), SGNORMALS::SetParent(), S3D::SGTYPE_COLORS, S3D::SGTYPE_COORDINDEX, S3D::SGTYPE_COORDS, S3D::SGTYPE_NORMALS, valid, and validated.

Referenced by AddChildNode(), and AddRefNode().

◆ addNodeRef()

void SGNODE::addNodeRef ( SGNODE aNode)
inherited

Add a pointer to a node which references this node, but does not own.

Such back-pointers are required to ensure that invalidated references are removed when a node is deleted.

Parameters
aNodeis the node holding a reference to this object.

Definition at line 170 of file sg_node.cpp.

171{
172 if( nullptr == aNode )
173 return;
174
175 std::list< SGNODE* >::iterator np =
176 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
177
178 if( np != m_BackPointers.end() )
179 return;
180
181 m_BackPointers.push_back( aNode );
182}
std::list< SGNODE * > m_BackPointers
nodes which hold a reference to this.
Definition: sg_node.h:226

References SGNODE::m_BackPointers.

Referenced by addNode(), SGSHAPE::addNode(), ReadCache(), and SGSHAPE::ReadCache().

◆ AddRefNode()

bool SGFACESET::AddRefNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 401 of file sg_faceset.cpp.

402{
403 return addNode( aNode, false );
404}

References addNode().

◆ AssociateWrapper()

void SGNODE::AssociateWrapper ( SGNODE **  aWrapperRef)
noexceptinherited

Associate this object with a handle to itself.

The handle is typically held by an IFSG* wrapper and the pointer which it refers to is set to NULL upon destruction of this object. This mechanism provides a scheme by which a wrapper can be notified of the destruction of the object which it wraps.

Definition at line 207 of file sg_node.cpp.

208{
209 wxCHECK( aWrapperRef && *aWrapperRef == this, /* void */ );
210
211 // if there is an existing association then break it and emit a warning
212 // just in case the behavior is undesired
213 if( m_Association )
214 {
215 *m_Association = nullptr;
216
217 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [WARNING] association being broken with "
218 "previous wrapper" ),
219 __FILE__, __FUNCTION__, __LINE__ );
220 }
221
222 m_Association = aWrapperRef;
223}
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition: sg_node.h:233

Referenced by S3D::AssociateSGNodeWrapper(), IFSG_APPEARANCE::Attach(), IFSG_COLORS::Attach(), IFSG_COORDINDEX::Attach(), IFSG_COORDS::Attach(), IFSG_FACESET::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_TRANSFORM::Attach(), IFSG_APPEARANCE::IFSG_APPEARANCE(), IFSG_COLORS::IFSG_COLORS(), IFSG_COORDINDEX::IFSG_COORDINDEX(), IFSG_COORDS::IFSG_COORDS(), IFSG_FACESET::IFSG_FACESET(), IFSG_NORMALS::IFSG_NORMALS(), IFSG_SHAPE::IFSG_SHAPE(), IFSG_TRANSFORM::IFSG_TRANSFORM(), IFSG_APPEARANCE::NewNode(), IFSG_COLORS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ CalcNormals()

bool SGFACESET::CalcNormals ( SGNODE **  aPtr)

Definition at line 975 of file sg_faceset.cpp.

976{
977 SGCOORDS* coords = m_Coords;
978
979 if( m_RCoords )
980 coords = m_RCoords;
981
982 if( nullptr == coords || coords->coords.empty() )
983 return false;
984
985 if( m_Normals && !m_Normals->norms.empty( ) )
986 return true;
987
988 if( m_RNormals && !m_RNormals->norms.empty( ) )
989 return true;
990
991 return coords->CalcNormals( this, aPtr );
992}
std::vector< SGPOINT > coords
Definition: sg_coords.h:72
bool CalcNormals(SGFACESET *callingNode, SGNODE **aPtr=nullptr)
Calculate normals for this coordinate list and sets the normals list in the parent SGFACESET.
Definition: sg_coords.cpp:309
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64

References SGCOORDS::CalcNormals(), SGCOORDS::coords, m_Coords, m_Normals, m_RCoords, m_RNormals, and SGNORMALS::norms.

◆ delNodeRef()

void SGNODE::delNodeRef ( const SGNODE aNode)
inherited

Remove a pointer to a node which references this node, but does not own.

Parameters
aNodeis the node holding a reference to this object.

Definition at line 185 of file sg_node.cpp.

186{
187 if( nullptr == aNode )
188 return;
189
190 std::list< SGNODE* >::iterator np =
191 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
192
193 if( np != m_BackPointers.end() )
194 {
195 m_BackPointers.erase( np );
196 return;
197 }
198
199 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] delNodeRef() did not find its target, this "
200 "node type %d, referenced node type %d" ),
201 __FILE__, __FUNCTION__, __LINE__,
202 m_SGtype,
203 aNode->GetNodeType() );
204}

References SGNODE::GetNodeType(), SGNODE::m_BackPointers, and SGNODE::m_SGtype.

Referenced by unlinkNode(), SGSHAPE::unlinkNode(), ~SGFACESET(), and SGSHAPE::~SGSHAPE().

◆ DisassociateWrapper()

void SGNODE::DisassociateWrapper ( SGNODE **  aWrapperRef)
noexceptinherited

Remove the association between an IFSG* wrapper object and this object.

Definition at line 225 of file sg_node.cpp.

226{
227 if( !m_Association )
228 return;
229
230 wxCHECK( aWrapperRef, /* void */ );
231
232 wxCHECK( *aWrapperRef == *m_Association && aWrapperRef == m_Association, /* void */ );
233
234 m_Association = nullptr;
235}

Referenced by IFSG_APPEARANCE::Attach(), IFSG_COLORS::Attach(), IFSG_COORDINDEX::Attach(), IFSG_COORDS::Attach(), IFSG_FACESET::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_TRANSFORM::Attach(), IFSG_NODE::Destroy(), IFSG_APPEARANCE::NewNode(), IFSG_COLORS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_TRANSFORM::NewNode(), and IFSG_NODE::~IFSG_NODE().

◆ FindNode()

SGNODE * SGFACESET::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtual

Search the tree of linked nodes and return a reference to the first node found with the given name.

The reference is then typically added to another node via AddRefNode().

Parameters
aNodeNameis the name of the node to search for.
aCalleris a pointer to the node invoking this function.
Returns
is a valid node pointer on success, otherwise NULL.

Implements SGNODE.

Definition at line 149 of file sg_faceset.cpp.

150{
151 if( nullptr == aNodeName || 0 == aNodeName[0] )
152 return nullptr;
153
154 if( !m_Name.compare( aNodeName ) )
155 return this;
156
157 SGNODE* np = nullptr;
158
159 if( m_Colors )
160 {
161 np = m_Colors->FindNode( aNodeName, this );
162
163 if( np )
164 return np;
165 }
166
167 if( m_Coords )
168 {
169 np = m_Coords->FindNode( aNodeName, this );
170
171 if( np )
172 return np;
173 }
174
175 if( m_CoordIndices )
176 {
177 np = m_CoordIndices->FindNode( aNodeName, this );
178
179 if( np )
180 return np;
181 }
182
183 if( m_Normals )
184 {
185 np = m_Normals->FindNode( aNodeName, this );
186
187 if( np )
188 return np;
189 }
190
191 // query the parent if appropriate
192 if( aCaller == m_Parent || nullptr == m_Parent )
193 return nullptr;
194
195 return m_Parent->FindNode( aNodeName, this );
196}
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_colors.cpp:88
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_coords.cpp:90
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_index.cpp:82
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
virtual SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller)=0
Search the tree of linked nodes and return a reference to the first node found with the given name.
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_normals.cpp:89

References SGCOLORS::FindNode(), SGCOORDS::FindNode(), SGINDEX::FindNode(), SGNORMALS::FindNode(), SGNODE::FindNode(), m_Colors, m_CoordIndices, m_Coords, SGNODE::m_Name, m_Normals, and SGNODE::m_Parent.

Referenced by SGSHAPE::FindNode(), and ReadCache().

◆ GatherCoordIndices()

void SGFACESET::GatherCoordIndices ( std::vector< int > &  aIndexList)

Add all internal coordinate indices to the given list in preparation for a normals calculation.

Definition at line 968 of file sg_faceset.cpp.

969{
970 if( m_CoordIndices )
971 m_CoordIndices->GatherCoordIndices( aIndexList );
972}
void GatherCoordIndices(std::vector< int > &aIndexList)
Add all coordinate indices to the given list in preparation for a normals calculation.

References SGCOORDINDEX::GatherCoordIndices(), and m_CoordIndices.

Referenced by SGCOORDS::CalcNormals().

◆ GetName()

◆ GetNodeType()

◆ GetNodeTypeName()

const char * SGNODE::GetNodeTypeName ( S3D::SGTYPES  aNodeType) const
noexceptinherited

Definition at line 164 of file sg_node.cpp.

165{
166 return node_names[aNodeType].c_str();
167}
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:36

References node_names.

Referenced by IFSG_NODE::GetNodeTypeName(), IFSG_APPEARANCE::NewNode(), IFSG_COLORS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ GetParent()

◆ isWritten()

bool SGNODE::isWritten ( void  )
inlinenoexceptinherited

Return true if the object had already been written to a cache file or VRML file.

For internal use only.

Definition at line 220 of file sg_node.h.

221 {
222 return m_written;
223 }
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230

References SGNODE::m_written.

Referenced by SCENEGRAPH::WriteCache(), WriteCache(), and SGSHAPE::WriteCache().

◆ ReadCache()

bool SGFACESET::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtual

Reads binary format data from a cache file.

To read a cache file, open the file for reading and invoke this function from a new SCENEGRAPH node.

Implements SGNODE.

Definition at line 601 of file sg_faceset.cpp.

602{
604 || m_RNormals )
605 {
606 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] non-empty node" ),
607 __FILE__, __FUNCTION__, __LINE__ );
608
609 return false;
610 }
611
612 #define NITEMS 7
613 bool items[NITEMS];
614
615 for( int i = 0; i < NITEMS; ++i )
616 aFile.read( (char*) &items[i], sizeof( bool ) );
617
618 if( ( items[0] && items[1] ) || ( items[3] && items[4] ) || ( items[5] && items[6] ) )
619 {
620 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; multiple item definitions "
621 "at position %d" ),
622 __FILE__, __FUNCTION__, __LINE__,
623 static_cast<int>( aFile.tellg() ) );
624
625 return false;
626 }
627
628 std::string name;
629
630 if( items[0] )
631 {
632 if( S3D::SGTYPE_COORDS != S3D::ReadTag( aFile, name ) )
633 {
634 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child coords tag at "
635 "position %d" ),
636 __FILE__, __FUNCTION__, __LINE__,
637 static_cast<int>( aFile.tellg() ) );
638
639 return false;
640 }
641
642 m_Coords = new SGCOORDS( this );
643 m_Coords->SetName( name.c_str() );
644
645 if( !m_Coords->ReadCache( aFile, this ) )
646 {
647 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; corrupt data while "
648 "reading coords '%s'" ),
649 __FILE__, __FUNCTION__, __LINE__,
650 name );
651
652 return false;
653 }
654 }
655
656 if( items[1] )
657 {
658 if( S3D::SGTYPE_COORDS != S3D::ReadTag( aFile, name ) )
659 {
660 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref coords tag at "
661 "position %d" ),
662 __FILE__, __FUNCTION__, __LINE__,
663 static_cast<int>( aFile.tellg() ) );
664
665 return false;
666 }
667
668 SGNODE* np = FindNode( name.c_str(), this );
669
670 if( !np )
671 {
672 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; cannot find ref "
673 "coords '%s'" ),
674 __FILE__, __FUNCTION__, __LINE__,
675 name );
676
677 return false;
678 }
679
680 if( S3D::SGTYPE_COORDS != np->GetNodeType() )
681 {
682 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; type is not SGCOORDS "
683 "'%s'" ),
684 __FILE__, __FUNCTION__, __LINE__,
685 name );
686
687 return false;
688 }
689
690 m_RCoords = (SGCOORDS*)np;
691 m_RCoords->addNodeRef( this );
692 }
693
694 if( items[2] )
695 {
696 if( S3D::SGTYPE_COORDINDEX != S3D::ReadTag( aFile, name ) )
697 {
698 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad coord index tag at "
699 "position %d" ),
700 __FILE__, __FUNCTION__, __LINE__,
701 static_cast<int>( aFile.tellg() ) );
702
703 return false;
704 }
705
706 m_CoordIndices = new SGCOORDINDEX( this );
707 m_CoordIndices->SetName( name.c_str() );
708
709 if( !m_CoordIndices->ReadCache( aFile, this ) )
710 {
711 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading coord "
712 "index '%s'" ),
713 __FILE__, __FUNCTION__, __LINE__,
714 name );
715
716 return false;
717 }
718 }
719
720 if( items[3] )
721 {
722 if( S3D::SGTYPE_NORMALS != S3D::ReadTag( aFile, name ) )
723 {
724 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child normals tag "
725 "at position %d" ),
726 __FILE__, __FUNCTION__, __LINE__,
727 static_cast<int>( aFile.tellg() ) );
728
729 return false;
730 }
731
732 m_Normals = new SGNORMALS( this );
733 m_Normals->SetName( name.c_str() );
734
735 if( !m_Normals->ReadCache( aFile, this ) )
736 {
737 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading normals "
738 "'%s'" ),
739 __FILE__, __FUNCTION__, __LINE__,
740 name );
741
742 return false;
743 }
744 }
745
746 if( items[4] )
747 {
748 if( S3D::SGTYPE_NORMALS != S3D::ReadTag( aFile, name ) )
749 {
750 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref normals tag at "
751 "position %d" ),
752 __FILE__, __FUNCTION__, __LINE__,
753 static_cast<int>( aFile.tellg() ) );
754
755 return false;
756 }
757
758 SGNODE* np = FindNode( name.c_str(), this );
759
760 if( !np )
761 {
762 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt: cannot find ref normals "
763 "'%s'" ),
764 __FILE__, __FUNCTION__, __LINE__,
765 name );
766
767 return false;
768 }
769
770 if( S3D::SGTYPE_NORMALS != np->GetNodeType() )
771 {
772 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt: type is not SGNORMALS '%s'" ),
773 __FILE__, __FUNCTION__, __LINE__,
774 name );
775
776 return false;
777 }
778
779 m_RNormals = (SGNORMALS*)np;
780 m_RNormals->addNodeRef( this );
781 }
782
783 if( items[5] )
784 {
785 if( S3D::SGTYPE_COLORS != S3D::ReadTag( aFile, name ) )
786 {
787 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad child colors tag "
788 "at position %d" ),
789 __FILE__, __FUNCTION__, __LINE__,
790 static_cast<int>( aFile.tellg() ) );
791
792 return false;
793 }
794
795 m_Colors = new SGCOLORS( this );
796 m_Colors->SetName( name.c_str() );
797
798 if( !m_Colors->ReadCache( aFile, this ) )
799 {
800 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data while reading colors "
801 "'%s'" ),
802 __FILE__, __FUNCTION__, __LINE__,
803 name );
804
805 return false;
806 }
807 }
808
809 if( items[6] )
810 {
811 if( S3D::SGTYPE_COLORS != S3D::ReadTag( aFile, name ) )
812 {
813 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data; bad ref colors tag at "
814 "position %d" ),
815 __FILE__, __FUNCTION__, __LINE__,
816 static_cast<int>( aFile.tellg() ) );
817
818 return false;
819 }
820
821 SGNODE* np = FindNode( name.c_str(), this );
822
823 if( !np )
824 {
825 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: cannot find ref colors "
826 "'%s'" ),
827 __FILE__, __FUNCTION__, __LINE__,
828 name );
829
830 return false;
831 }
832
833 if( S3D::SGTYPE_COLORS != np->GetNodeType() )
834 {
835 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] corrupt data: type is not SGCOLORS "
836 "'%s'" ),
837 __FILE__, __FUNCTION__, __LINE__,
838 name );
839
840 return false;
841 }
842
843 m_RColors = (SGCOLORS*)np;
844 m_RColors->addNodeRef( this );
845 }
846
847 if( aFile.fail() )
848 return false;
849
850 return true;
851}
const char * name
Definition: DXF_plotter.cpp:56
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: sg_colors.cpp:284
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: sg_coords.cpp:286
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_faceset.cpp:149
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: sg_index.cpp:307
void SetName(const char *aName)
Definition: sg_node.cpp:155
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: sg_normals.cpp:279
S3D::SGTYPES ReadTag(std::istream &aFile, std::string &aName)
Read the text tag of a binary cache file which is the NodeTag and unique ID number combined.
Definition: sg_helpers.cpp:195
#define NITEMS

References SGNODE::addNodeRef(), FindNode(), SGNODE::GetNodeType(), m_Colors, m_CoordIndices, m_Coords, m_Normals, m_RColors, m_RCoords, m_RNormals, name, NITEMS, SGCOLORS::ReadCache(), SGCOORDS::ReadCache(), SGINDEX::ReadCache(), SGNORMALS::ReadCache(), S3D::ReadTag(), SGNODE::SetName(), S3D::SGTYPE_COLORS, S3D::SGTYPE_COORDINDEX, S3D::SGTYPE_COORDS, and S3D::SGTYPE_NORMALS.

Referenced by SGSHAPE::ReadCache().

◆ ReNameNodes()

void SGFACESET::ReNameNodes ( void  )
overridevirtual

Rename a node and all its child nodes in preparation for write operations.

Implements SGNODE.

Definition at line 413 of file sg_faceset.cpp.

414{
415 m_written = false;
416
417 // rename this node
418 m_Name.clear();
419 GetName();
420
421 // rename all Colors and Indices
422 if( m_Colors )
424
425 // rename all Coordinates and Indices
426 if( m_Coords )
428
429 if( m_CoordIndices )
431
432 // rename all Normals and Indices
433 if( m_Normals )
435}
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: sg_colors.cpp:171
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: sg_coords.cpp:169
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: sg_index.cpp:161
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: sg_normals.cpp:168

References SGNODE::GetName(), m_Colors, m_CoordIndices, m_Coords, SGNODE::m_Name, m_Normals, SGNODE::m_written, SGCOLORS::ReNameNodes(), SGCOORDS::ReNameNodes(), SGINDEX::ReNameNodes(), and SGNORMALS::ReNameNodes().

Referenced by SGSHAPE::ReNameNodes().

◆ ResetNodeIndex()

void SGNODE::ResetNodeIndex ( void  )
noexceptinherited

Reset the global SG* node indices in preparation for write operations.

Definition at line 238 of file sg_node.cpp.

239{
240 for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
241 node_counts[i] = 1;
242}
@ SGTYPE_END
Definition: sg_types.h:45
static unsigned int node_counts[S3D::SGTYPE_END]
Definition: sg_node.cpp:50

References node_counts, and S3D::SGTYPE_END.

Referenced by S3D::ResetNodeIndex(), SCENEGRAPH::WriteCache(), and S3D::WriteVRML().

◆ SetName()

void SGNODE::SetName ( const char *  aName)
inherited

Definition at line 155 of file sg_node.cpp.

156{
157 if( nullptr == aName || 0 == aName[0] )
159 else
160 m_Name = aName;
161}

References getNodeName(), SGNODE::m_Name, and SGNODE::m_SGtype.

Referenced by SCENEGRAPH::ReadCache(), ReadCache(), SGSHAPE::ReadCache(), and IFSG_NODE::SetName().

◆ SetParent()

bool SGFACESET::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtual

Set the parent SGNODE of this object.

Parameters
aParent[in] is the desired parent node
Returns
true if the operation succeeds; false if the given node is not allowed to be a parent to the derived object.

Implements SGNODE.

Definition at line 119 of file sg_faceset.cpp.

120{
121 if( nullptr != m_Parent )
122 {
123 if( aParent == m_Parent )
124 return true;
125
126 // handle the change in parents
127 if( notify )
128 m_Parent->unlinkChildNode( this );
129
130 m_Parent = nullptr;
131
132 if( nullptr == aParent )
133 return true;
134 }
135
136 // only a SGSHAPE may be parent to a SGFACESET
137 if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
138 return false;
139
140 m_Parent = aParent;
141
142 if( m_Parent )
143 m_Parent->AddChildNode( this );
144
145 return true;
146}
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, S3D::SGTYPE_SHAPE, and SGNODE::unlinkChildNode().

Referenced by SGSHAPE::addNode(), and SGSHAPE::~SGSHAPE().

◆ SwapParent()

bool SGNODE::SwapParent ( SGNODE aNewParent)
inherited

Swap the ownership with the given parent.

This operation may be required when reordering nodes for optimization.

Parameters
aNewParentwill become the new parent to the object; it must be the same type as the parent of this instance.

Definition at line 116 of file sg_node.cpp.

117{
118 if( aNewParent == m_Parent )
119 return true;
120
121 if( nullptr == aNewParent )
122 return false;
123
124 if( nullptr == m_Parent )
125 {
126 if( aNewParent->AddChildNode( this ) )
127 return true;
128
129 return false;
130 }
131
132 if( aNewParent->GetNodeType() != m_Parent->GetNodeType() )
133 return false;
134
135 SGNODE* oldParent = m_Parent;
136 m_Parent->unlinkChildNode( this );
137 m_Parent = nullptr;
138 aNewParent->unlinkRefNode( this );
139 aNewParent->AddChildNode( this );
140 oldParent->AddRefNode( this );
141
142 return true;
143}
virtual bool AddRefNode(SGNODE *aNode)=0
virtual void unlinkRefNode(const SGNODE *aNode)=0
Remove pointers to a referenced node.

References SGNODE::AddChildNode(), SGNODE::AddRefNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::unlinkChildNode(), and SGNODE::unlinkRefNode().

Referenced by WriteCache(), and SGSHAPE::WriteCache().

◆ unlinkChildNode()

void SGFACESET::unlinkChildNode ( const SGNODE aNode)
overridevirtual

Remove references to an owned child.

This is invoked by the child upon destruction to ensure that the parent has no invalid references.

Parameters
aNodeis the child which is being deleted.

Implements SGNODE.

Definition at line 262 of file sg_faceset.cpp.

263{
264 unlinkNode( aNode, true );
265}
void unlinkNode(const SGNODE *aNode, bool isChild)
Definition: sg_faceset.cpp:199

References unlinkNode().

◆ unlinkNode()

void SGFACESET::unlinkNode ( const SGNODE aNode,
bool  isChild 
)
private

Definition at line 199 of file sg_faceset.cpp.

200{
201 if( nullptr == aNode )
202 return;
203
204 valid = false;
205 validated = false;
206
207 if( isChild )
208 {
209 if( aNode == m_Colors )
210 {
211 m_Colors = nullptr;
212 return;
213 }
214
215 if( aNode == m_Coords )
216 {
217 m_Coords = nullptr;
218 return;
219 }
220
221 if( aNode == m_Normals )
222 {
223 m_Normals = nullptr;
224 return;
225 }
226
227 if( aNode == m_CoordIndices )
228 {
229 m_CoordIndices = nullptr;
230 return;
231 }
232 }
233 else
234 {
235 if( aNode == m_RColors )
236 {
237 delNodeRef( this );
238 m_RColors = nullptr;
239 return;
240 }
241
242 if( aNode == m_RCoords )
243 {
244 delNodeRef( this );
245 m_RCoords = nullptr;
246 return;
247 }
248
249 if( aNode == m_RNormals )
250 {
251 delNodeRef( this );
252 m_RNormals = nullptr;
253 return;
254 }
255 }
256
257 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] unlinkNode() did not find its target" ),
258 __FILE__, __FUNCTION__, __LINE__ );
259}

References SGNODE::delNodeRef(), m_Colors, m_CoordIndices, m_Coords, m_Normals, m_RColors, m_RCoords, m_RNormals, valid, and validated.

Referenced by unlinkChildNode(), and unlinkRefNode().

◆ unlinkRefNode()

void SGFACESET::unlinkRefNode ( const SGNODE aNode)
overridevirtual

Remove pointers to a referenced node.

This is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references.

Parameters
aNodeis the node which is being deleted.

Implements SGNODE.

Definition at line 268 of file sg_faceset.cpp.

269{
270 unlinkNode( aNode, false );
271}

References unlinkNode().

◆ validate()

bool SGFACESET::validate ( void  )

Definition at line 854 of file sg_faceset.cpp.

855{
856 // verify the integrity of this object's data
857 if( validated )
858 return valid;
859
860 // ensure we have at least coordinates and their normals
861 if( ( nullptr == m_Coords && nullptr == m_RCoords )
862 || ( nullptr == m_Normals && nullptr == m_RNormals )
863 || ( nullptr == m_CoordIndices ) )
864 {
865 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; no vertices, vertex indices, "
866 "or normals" ),
867 __FILE__, __FUNCTION__, __LINE__ );
868
869 validated = true;
870 valid = false;
871 return false;
872 }
873
874 // check that there are >3 vertices
875 SGCOORDS* coords = m_Coords;
876
877 if( nullptr == coords )
878 coords = m_RCoords;
879
880 size_t nCoords = 0;
881 SGPOINT* lCoords = nullptr;
882 coords->GetCoordsList( nCoords, lCoords );
883
884 if( nCoords < 3 )
885 {
886 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; fewer than 3 vertices" ),
887 __FILE__, __FUNCTION__, __LINE__ );
888
889 validated = true;
890 valid = false;
891 return false;
892 }
893
894 // check that nVertices is divisible by 3 (facets are triangles)
895 size_t nCIdx = 0;
896 int* lCIdx = nullptr;
897 m_CoordIndices->GetIndices( nCIdx, lCIdx );
898
899 if( nCIdx < 3 || ( nCIdx % 3 > 0 ) )
900 {
901 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; no vertex indices or not "
902 "multiple of 3" ),
903 __FILE__, __FUNCTION__, __LINE__ );
904
905 validated = true;
906 valid = false;
907 return false;
908 }
909
910 // check that vertex[n] >= 0 and < nVertices
911 for( size_t i = 0; i < nCIdx; ++i )
912 {
913 if( lCIdx[i] < 0 || lCIdx[i] >= (int)nCoords )
914 {
915 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; vertex index out of "
916 "bounds" ),
917 __FILE__, __FUNCTION__, __LINE__ );
918
919 validated = true;
920 valid = false;
921 return false;
922 }
923 }
924
925 // check that there are as many normals as vertices
926 size_t nNorms = 0;
927 SGVECTOR* lNorms = nullptr;
928 SGNORMALS* pNorms = m_Normals;
929
930 if( nullptr == pNorms )
931 pNorms = m_RNormals;
932
933 pNorms->GetNormalList( nNorms, lNorms );
934
935 if( nNorms != nCoords )
936 {
937 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad model; number of normals (%ul) does "
938 "not match number of vertices (%ul)" ),
939 __FILE__, __FUNCTION__, __LINE__,
940 static_cast<unsigned long>( nNorms ),
941 static_cast<unsigned long>( nCoords ) );
942
943 validated = true;
944 valid = false;
945 return false;
946 }
947
948 // if there are colors then ensure there are as many colors as vertices
949 SGCOLORS* pColors = m_Colors;
950
951 if( nullptr == pColors )
952 pColors = m_RColors;
953
954 if( nullptr != pColors )
955 {
956 // we must have at least as many colors as vertices
957 size_t nColor = 0;
958 SGCOLOR* pColor = nullptr;
959 pColors->GetColorList( nColor, pColor );
960 }
961
962 validated = true;
963 valid = true;
964 return true;
965}
bool GetColorList(size_t &aListSize, SGCOLOR *&aColorList)
Definition: sg_colors.cpp:128
bool GetCoordsList(size_t &aListSize, SGPOINT *&aCoordsList)
Definition: sg_coords.cpp:130
bool GetIndices(size_t &nIndices, int *&aIndexList)
Retrieve the number of indices and a pointer to the list.
Definition: sg_index.cpp:126
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
Definition: sg_normals.cpp:129

References SGCOLORS::GetColorList(), SGCOORDS::GetCoordsList(), SGINDEX::GetIndices(), SGNORMALS::GetNormalList(), m_Colors, m_CoordIndices, m_Coords, m_Normals, m_RColors, m_RCoords, m_RNormals, valid, and validated.

Referenced by SGSHAPE::Prepare().

◆ WriteCache()

bool SGFACESET::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtual

Write this node's data to a binary cache file.

The data includes all data of children and references to children. If this function is invoked by the user, parentNode must be set to NULL in order to ensure coherent data.

Implements SGNODE.

Definition at line 493 of file sg_faceset.cpp.

494{
495 if( nullptr == parentNode )
496 {
497 wxCHECK( m_Parent, false );
498
499 SGNODE* np = m_Parent;
500
501 while( nullptr != np->GetParent() )
502 np = np->GetParent();
503
504 if( np->WriteCache( aFile, nullptr ) )
505 {
506 m_written = true;
507 return true;
508 }
509
510 return false;
511 }
512
513 wxCHECK( parentNode == m_Parent, false );
514
515 if( !aFile.good() )
516 {
517 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
518 __FILE__, __FUNCTION__, __LINE__ );
519
520 return false;
521 }
522
523 // check if any references are unwritten and swap parents if so
524 if( nullptr != m_RCoords && !m_RCoords->isWritten() )
525 m_RCoords->SwapParent( this );
526
527 if( nullptr != m_RNormals && !m_RNormals->isWritten() )
528 m_RNormals->SwapParent( this );
529
530 if( nullptr != m_RColors && !m_RColors->isWritten() )
531 m_RColors->SwapParent( this );
532
533 aFile << "[" << GetName() << "]";
534 #define NITEMS 7
535 bool items[NITEMS];
536 int i;
537
538 for( i = 0; i < NITEMS; ++i )
539 items[i] = 0;
540
541 i = 0;
542 if( nullptr != m_Coords )
543 items[i] = true;
544
545 ++i;
546 if( nullptr != m_RCoords )
547 items[i] = true;
548
549 ++i;
550 if( nullptr != m_CoordIndices )
551 items[i] = true;
552
553 ++i;
554 if( nullptr != m_Normals )
555 items[i] = true;
556
557 ++i;
558 if( nullptr != m_RNormals )
559 items[i] = true;
560
561 ++i;
562 if( nullptr != m_Colors )
563 items[i] = true;
564
565 ++i;
566 if( nullptr != m_RColors )
567 items[i] = true;
568
569 for( int jj = 0; jj < NITEMS; ++jj )
570 aFile.write( (char*) &items[jj], sizeof( bool ) );
571
572 if( items[0] )
573 m_Coords->WriteCache( aFile, this );
574
575 if( items[1] )
576 aFile << "[" << m_RCoords->GetName() << "]";
577
578 if( items[2] )
579 m_CoordIndices->WriteCache( aFile, this );
580
581 if( items[3] )
582 m_Normals->WriteCache( aFile, this );
583
584 if( items[4] )
585 aFile << "[" << m_RNormals->GetName() << "]";
586
587 if( items[5] )
588 m_Colors->WriteCache( aFile, this );
589
590 if( items[6] )
591 aFile << "[" << m_RColors->GetName() << "]";
592
593 if( aFile.fail() )
594 return false;
595
596 m_written = true;
597 return true;
598}
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: sg_colors.cpp:239
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: sg_coords.cpp:241
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: sg_index.cpp:262
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
bool isWritten(void) noexcept
Return true if the object had already been written to a cache file or VRML file.
Definition: sg_node.h:220
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition: sg_node.cpp:110
bool SwapParent(SGNODE *aNewParent)
Swap the ownership with the given parent.
Definition: sg_node.cpp:116
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: sg_normals.cpp:234

References SGNODE::GetName(), SGNODE::GetParent(), SGNODE::isWritten(), m_Colors, m_CoordIndices, m_Coords, m_Normals, SGNODE::m_Parent, m_RColors, m_RCoords, m_RNormals, SGNODE::m_written, NITEMS, SGNODE::SwapParent(), SGCOLORS::WriteCache(), SGCOORDS::WriteCache(), SGINDEX::WriteCache(), SGNORMALS::WriteCache(), and SGNODE::WriteCache().

Referenced by SGSHAPE::WriteCache().

◆ WriteVRML()

bool SGFACESET::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtual

Writes this node's data to a VRML file.

This includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 438 of file sg_faceset.cpp.

439{
440 if( ( nullptr == m_Coords && nullptr == m_RCoords ) || ( nullptr == m_CoordIndices ) )
441 {
442 return false;
443 }
444
445 if( aReuseFlag )
446 {
447 if( !m_written )
448 {
449 aFile << " geometry DEF " << GetName() << " IndexedFaceSet {\n";
450 m_written = true;
451 }
452 else
453 {
454 aFile << "USE " << GetName() << "\n";
455 return true;
456 }
457 }
458 else
459 {
460 aFile << " geometry IndexedFaceSet {\n";
461 }
462
463 if( m_Coords )
464 m_Coords->WriteVRML( aFile, aReuseFlag );
465
466 if( m_RCoords )
467 m_RCoords->WriteVRML( aFile, aReuseFlag );
468
469 if( m_CoordIndices )
470 m_CoordIndices->WriteVRML( aFile, aReuseFlag );
471
472 if( m_Normals || m_RNormals )
473 aFile << " normalPerVertex TRUE\n";
474
475 if( m_Normals )
476 m_Normals->WriteVRML( aFile, aReuseFlag );
477
478 if( m_RNormals )
479 m_RNormals->WriteVRML( aFile, aReuseFlag );
480
481 if( m_Colors )
482 m_Colors->WriteVRML( aFile, aReuseFlag );
483
484 if( m_RColors )
485 m_RColors->WriteVRML( aFile, aReuseFlag );
486
487 aFile << "}\n";
488
489 return true;
490}
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: sg_colors.cpp:181
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: sg_coords.cpp:179
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: sg_index.cpp:171
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: sg_normals.cpp:178

References SGNODE::GetName(), m_Colors, m_CoordIndices, m_Coords, m_Normals, m_RColors, m_RCoords, m_RNormals, SGNODE::m_written, SGCOLORS::WriteVRML(), SGCOORDS::WriteVRML(), SGINDEX::WriteVRML(), and SGNORMALS::WriteVRML().

Referenced by SGSHAPE::WriteVRML().

Member Data Documentation

◆ m_Association

SGNODE** SGNODE::m_Association
privateinherited

Handle to the instance held by a wrapper.

Definition at line 233 of file sg_node.h.

Referenced by SGNODE::SGNODE(), and SGNODE::~SGNODE().

◆ m_BackPointers

std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited

nodes which hold a reference to this.

Definition at line 226 of file sg_node.h.

Referenced by SGNODE::addNodeRef(), SGCOORDS::CalcNormals(), SGNODE::delNodeRef(), and SGNODE::~SGNODE().

◆ m_Colors

◆ m_CoordIndices

◆ m_Coords

◆ m_Name

◆ m_Normals

◆ m_Parent

◆ m_RColors

SGCOLORS* SGFACESET::m_RColors

◆ m_RCoords

◆ m_RNormals

◆ m_SGtype

◆ m_written

◆ valid

bool SGFACESET::valid
private

Definition at line 90 of file sg_faceset.h.

Referenced by addNode(), SGFACESET(), unlinkNode(), and validate().

◆ validated

bool SGFACESET::validated
private

Definition at line 91 of file sg_faceset.h.

Referenced by addNode(), SGFACESET(), unlinkNode(), and validate().


The documentation for this class was generated from the following files: