KiCad PCB EDA Suite
SGCOORDINDEX Class Reference

An object to maintain a coordinate index list. More...

#include <sg_coordindex.h>

Inheritance diagram for SGCOORDINDEX:
SGINDEX SGNODE

Public Member Functions

 SGCOORDINDEX (SGNODE *aParent)
 
virtual ~SGCOORDINDEX ()
 
void GatherCoordIndices (std::vector< int > &aIndexList)
 Add all coordinate indices to the given list in preparation for a normals calculation. More...
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set the parent SGNODE of this object. More...
 
SGNODEFindNode (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. More...
 
bool AddRefNode (SGNODE *aNode) noexcept override
 
bool AddChildNode (SGNODE *aNode) noexcept override
 
void unlinkChildNode (const SGNODE *aCaller) noexcept override
 Remove references to an owned child. More...
 
void unlinkRefNode (const SGNODE *aCaller) noexcept override
 Remove pointers to a referenced node. More...
 
bool GetIndices (size_t &nIndices, int *&aIndexList)
 Retrieve the number of indices and a pointer to the list. More...
 
void SetIndices (size_t nIndices, int *aIndexList)
 Set the number of indices and creates a copy of the given index data. More...
 
void AddIndex (int aIndex)
 Add a single index to the list. More...
 
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...
 
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

std::vector< int > index
 

Protected Member Functions

bool writeCoordIndex (std::ostream &aFile)
 
bool writeColorIndex (std::ostream &aFile)
 
bool writeIndexList (std::ostream &aFile)
 

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...
 

Detailed Description

An object to maintain a coordinate index list.

Users must ensure that coordinate indices are specified as triplets (triangular faces) since no checking is performed. In instances where it is not possible to determine which side of the triangle is to be rendered (for example IGES entities) then the user must supply each triplet in both point orders.

Definition at line 42 of file sg_coordindex.h.

Constructor & Destructor Documentation

◆ SGCOORDINDEX()

SGCOORDINDEX::SGCOORDINDEX ( SGNODE aParent)

Definition at line 28 of file sg_coordindex.cpp.

28  : SGINDEX( aParent )
29 {
31 
32  if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
33  {
34  m_Parent->AddChildNode( this );
35  }
36 }
SGINDEX(SGNODE *aParent)
Definition: sg_index.cpp:32
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
virtual bool AddChildNode(SGNODE *aNode)=0
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::m_SGtype, S3D::SGTYPE_COORDINDEX, and S3D::SGTYPE_FACESET.

◆ ~SGCOORDINDEX()

SGCOORDINDEX::~SGCOORDINDEX ( )
virtual

Definition at line 39 of file sg_coordindex.cpp.

40 {
41 }

Member Function Documentation

◆ AddChildNode()

bool SGINDEX::AddChildNode ( SGNODE aNode)
overridevirtualnoexceptinherited

Implements SGNODE.

Definition at line 115 of file sg_index.cpp.

116 {
117  // Node should have no children or refs.
118  wxCHECK( false, false );
119 
120  return false;
121 }

◆ AddIndex()

void SGINDEX::AddIndex ( int  aIndex)
inherited

Add a single index to the list.

Parameters
aIndexis the index to add.

Definition at line 153 of file sg_index.cpp.

154 {
155  index.push_back( aIndex );
156 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

◆ 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 SGSHAPE::addNode(), SGFACESET::addNode(), SGSHAPE::ReadCache(), and SGFACESET::ReadCache().

◆ AddRefNode()

bool SGINDEX::AddRefNode ( SGNODE aNode)
overridevirtualnoexceptinherited

Implements SGNODE.

Definition at line 106 of file sg_index.cpp.

107 {
108  // Node should have no children or refs.
109  wxCHECK( false, false );
110 
111  return false;
112 }

◆ 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 205 of file sg_node.cpp.

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

Referenced by S3D::AssociateSGNodeWrapper(), IFSG_APPEARANCE::Attach(), IFSG_COORDINDEX::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_COORDS::Attach(), IFSG_FACESET::Attach(), IFSG_COLORS::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_SHAPE::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ 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, "%s:%s:%d * [BUG] delNodeRef() did not find its target, "
200  "this node type %d, referenced node type %d", __FILE__, __FUNCTION__, __LINE__,
201  m_SGtype, aNode->GetNodeType() );
202 }
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
std::list< SGNODE * > m_BackPointers
nodes which hold a reference to this.
Definition: sg_node.h:226
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

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

Referenced by SGSHAPE::unlinkNode(), SGFACESET::unlinkNode(), SGFACESET::~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 223 of file sg_node.cpp.

224 {
225  if( !m_Association )
226  return;
227 
228  wxCHECK( aWrapperRef, /* void */ );
229 
230  wxCHECK( *aWrapperRef == *m_Association && aWrapperRef == m_Association, /* void */ );
231 
232  m_Association = nullptr;
233 }
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition: sg_node.h:233

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

◆ FindNode()

SGNODE * SGINDEX::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtualnoexceptinherited

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 80 of file sg_index.cpp.

81 {
82  if( nullptr == aNodeName || 0 == aNodeName[0] )
83  return nullptr;
84 
85  if( !m_Name.compare( aNodeName ) )
86  return this;
87 
88  return nullptr;
89 }
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

Referenced by SGFACESET::FindNode().

◆ GatherCoordIndices()

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

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

Definition at line 44 of file sg_coordindex.cpp.

45 {
46  if( index.empty() )
47  return;
48 
49  aIndexList.insert( aIndexList.end(), index.begin(), index.end() );
50 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

Referenced by SGFACESET::GatherCoordIndices().

◆ GetIndices()

bool SGINDEX::GetIndices ( size_t &  nIndices,
int *&  aIndexList 
)
inherited

Retrieve the number of indices and a pointer to the list.

Note
The returned pointer may be invalidated by future operations on the SGNODE. The caller must make immediate use of the data and must not rely on the pointer's validity in the future.
Parameters
nIndiceswill hold the number of indices in the list.
aIndexListwill store a pointer to the data.
Returns
true if there was available data (nIndices > 0) otherwise false.

Definition at line 124 of file sg_index.cpp.

125 {
126  if( index.empty() )
127  {
128  nIndices = 0;
129  aIndexList = nullptr;
130  return false;
131  }
132 
133  nIndices = index.size();
134  aIndexList = & index[0];
135  return true;
136 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

Referenced by SGSHAPE::Prepare(), and SGFACESET::validate().

◆ 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_COORDS::NewNode(), IFSG_NORMALS::NewNode(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ GetParent()

SGNODE * SGNODE::GetParent ( void  ) const
noexceptinherited

Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.

top level transform).

Definition at line 110 of file sg_node.cpp.

111 {
112  return m_Parent;
113 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227

Referenced by IFSG_NODE::GetParent(), S3D::GetSGNodeParent(), IFSG_APPEARANCE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), SGSHAPE::WriteCache(), SGNORMALS::WriteCache(), SCENEGRAPH::WriteCache(), SGCOLORS::WriteCache(), SGFACESET::WriteCache(), SGCOORDS::WriteCache(), SGAPPEARANCE::WriteCache(), and SGINDEX::WriteCache().

◆ 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 SGSHAPE::WriteCache(), SCENEGRAPH::WriteCache(), and SGFACESET::WriteCache().

◆ ReadCache()

bool SGINDEX::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtualinherited

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 305 of file sg_index.cpp.

306 {
307  wxCHECK( index.empty(), false );
308 
309  size_t npts;
310  aFile.read( (char*)&npts, sizeof(size_t) );
311  int tmp;
312 
313  if( aFile.fail() )
314  return false;
315 
316  for( size_t i = 0; i < npts; ++i )
317  {
318  aFile.read( (char*) &tmp, sizeof( int ) );
319 
320  if( aFile.fail() )
321  return false;
322 
323  index.push_back( tmp );
324  }
325 
326  return true;
327 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

Referenced by SGFACESET::ReadCache().

◆ ReNameNodes()

void SGINDEX::ReNameNodes ( void  )
overridevirtualinherited

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

Implements SGNODE.

Definition at line 159 of file sg_index.cpp.

160 {
161  m_written = false;
162 
163  // rename this node
164  m_Name.clear();
165  GetName();
166 }
const char * GetName(void)
Definition: sg_node.cpp:146
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

References SGNODE::GetName(), SGNODE::m_Name, and SGNODE::m_written.

Referenced by SGFACESET::ReNameNodes().

◆ ResetNodeIndex()

void SGNODE::ResetNodeIndex ( void  )
noexceptinherited

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

Definition at line 236 of file sg_node.cpp.

237 {
238  for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
239  node_counts[i] = 1;
240 }
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().

◆ SetIndices()

void SGINDEX::SetIndices ( size_t  nIndices,
int *  aIndexList 
)
inherited

Set the number of indices and creates a copy of the given index data.

Parameters
nIndicesthe number of indices to be stored.
aIndexListthe index data.

Definition at line 139 of file sg_index.cpp.

140 {
141  index.clear();
142 
143  if( 0 == nIndices || nullptr == aIndexList )
144  return;
145 
146  for( size_t i = 0; i < nIndices; ++i )
147  index.push_back( aIndexList[i] );
148 
149  return;
150 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

◆ 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 }
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
static void getNodeName(S3D::SGTYPES nodeType, std::string &aName)
Definition: sg_node.cpp:59

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

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

◆ SetParent()

bool SGINDEX::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtualinherited

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 50 of file sg_index.cpp.

51 {
52  if( nullptr != m_Parent )
53  {
54  if( aParent == m_Parent )
55  return true;
56 
57  // handle the change in parents
58  if( notify )
59  m_Parent->unlinkChildNode( this );
60 
61  m_Parent = nullptr;
62 
63  if( nullptr == aParent )
64  return true;
65  }
66 
67  // only a SGFACESET may be parent to a SGINDEX and derived types
68  if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
69  return false;
70 
71  m_Parent = aParent;
72 
73  if( m_Parent )
74  m_Parent->AddChildNode( this );
75 
76  return true;
77 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.
virtual bool AddChildNode(SGNODE *aNode)=0
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

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

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

◆ 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
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
virtual void unlinkRefNode(const SGNODE *aNode)=0
Remove pointers to a referenced node.
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.
virtual bool AddChildNode(SGNODE *aNode)=0
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104

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

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

◆ unlinkChildNode()

void SGINDEX::unlinkChildNode ( const SGNODE aNode)
overridevirtualnoexceptinherited

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 92 of file sg_index.cpp.

93 {
94  // Node should have no children or refs.
95  wxCHECK( false, /* void */ );
96 }

◆ unlinkRefNode()

void SGINDEX::unlinkRefNode ( const SGNODE aNode)
overridevirtualnoexceptinherited

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 99 of file sg_index.cpp.

100 {
101  // Node should have no children or refs.
102  wxCHECK( false, /* void */ );
103 }

◆ WriteCache()

bool SGINDEX::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtualinherited

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 260 of file sg_index.cpp.

261 {
262  if( nullptr == parentNode )
263  {
264  wxCHECK( m_Parent, false );
265 
266  SGNODE* np = m_Parent;
267 
268  while( nullptr != np->GetParent() )
269  np = np->GetParent();
270 
271  if( np->WriteCache( aFile, nullptr ) )
272  {
273  m_written = true;
274  return true;
275  }
276 
277  return false;
278  }
279 
280  wxCHECK( parentNode == m_Parent, false );
281 
282  if( !aFile.good() )
283  {
284  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] bad stream",
285  __FILE__, __FUNCTION__, __LINE__ );
286 
287  return false;
288  }
289 
290  aFile << "[" << GetName() << "]";
291  size_t npts = index.size();
292  aFile.write( (char*)&npts, sizeof(size_t) );
293 
294  for( size_t i = 0; i < npts; ++i )
295  aFile.write( (char*)&index[i], sizeof(int) );
296 
297  if( aFile.fail() )
298  return false;
299 
300  m_written = true;
301  return true;
302 }
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
std::vector< int > index
Definition: sg_index.h:95
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
const char * GetName(void)
Definition: sg_node.cpp:146
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
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
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.

References SGNODE::GetName(), SGNODE::GetParent(), SGINDEX::index, SGNODE::m_Parent, SGNODE::m_written, and SGNODE::WriteCache().

Referenced by SGFACESET::WriteCache().

◆ writeColorIndex()

bool SGINDEX::writeColorIndex ( std::ostream &  aFile)
protectedinherited

Definition at line 224 of file sg_index.cpp.

225 {
226  aFile << " colorIndex [\n ";
227  return writeIndexList( aFile );
228 }
bool writeIndexList(std::ostream &aFile)
Definition: sg_index.cpp:231

References SGINDEX::writeIndexList().

Referenced by SGINDEX::WriteVRML().

◆ writeCoordIndex()

bool SGINDEX::writeCoordIndex ( std::ostream &  aFile)
protectedinherited

Definition at line 181 of file sg_index.cpp.

182 {
183  size_t n = index.size();
184 
185  wxCHECK_MSG( n % 3 == 0, false,
186  "Coordinate index is not divisible by three (violates triangle constraint)" );
187 
188  aFile << " coordIndex [\n ";
189 
190  // indices to control formatting
191  int nv0 = 0;
192  int nv1 = 0;
193 
194  for( size_t i = 0; i < n; )
195  {
196  aFile << index[i];
197  ++i;
198 
199  if( ++nv0 == 3 )
200  {
201  aFile << ",-1";
202  ++nv1;
203  nv0 = 0;
204  }
205 
206  if( i < n )
207  {
208  aFile << ",";
209 
210  if( nv1 == 8 )
211  {
212  nv1 = 0;
213  aFile << "\n ";
214  }
215  }
216  }
217 
218  aFile << "]\n";
219 
220  return true;
221 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

Referenced by SGINDEX::WriteVRML().

◆ writeIndexList()

bool SGINDEX::writeIndexList ( std::ostream &  aFile)
protectedinherited

Definition at line 231 of file sg_index.cpp.

232 {
233  // index to control formatting
234  int nv = 0;
235  size_t n = index.size();
236 
237  for( size_t i = 0; i < n; )
238  {
239  aFile << index[i];
240  ++i;
241 
242  if( i < n )
243  {
244  aFile << ",";
245 
246  if( ++nv == 20 )
247  {
248  aFile << "\n ";
249  nv = 0;
250  }
251  }
252  }
253 
254  aFile << "]\n";
255 
256  return true;
257 }
std::vector< int > index
Definition: sg_index.h:95

References SGINDEX::index.

Referenced by SGINDEX::writeColorIndex().

◆ WriteVRML()

bool SGINDEX::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtualinherited

Writes this node's data to a VRML file.

This includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 169 of file sg_index.cpp.

170 {
171  if( index.empty() )
172  return false;
173 
175  return writeCoordIndex( aFile );
176 
177  return writeColorIndex( aFile );
178 }
bool writeColorIndex(std::ostream &aFile)
Definition: sg_index.cpp:224
std::vector< int > index
Definition: sg_index.h:95
bool writeCoordIndex(std::ostream &aFile)
Definition: sg_index.cpp:181
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228

References SGINDEX::index, SGNODE::m_SGtype, S3D::SGTYPE_COORDINDEX, SGINDEX::writeColorIndex(), and SGINDEX::writeCoordIndex().

Referenced by SGFACESET::WriteVRML().

Member Data Documentation

◆ index

◆ 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_Name

◆ m_Parent

◆ m_SGtype

◆ m_written


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