KiCad PCB EDA Suite
SGAPPEARANCE Class Reference

#include <sg_appearance.h>

Inheritance diagram for SGAPPEARANCE:
SGNODE

Public Member Functions

void unlinkChildNode (const SGNODE *aNode) override
 Function unlinkChild removes references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
void unlinkRefNode (const SGNODE *aNode) override
 Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references. More...
 
 SGAPPEARANCE (SGNODE *aParent)
 
virtual ~SGAPPEARANCE ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Function SetParent sets the parent SGNODE of this object. More...
 
bool SetEmissive (float aRVal, float aGVal, float aBVal)
 
bool SetEmissive (const SGCOLOR *aRGBColor)
 
bool SetEmissive (const SGCOLOR &aRGBColor)
 
bool SetDiffuse (float aRVal, float aGVal, float aBVal)
 
bool SetDiffuse (const SGCOLOR *aRGBColor)
 
bool SetDiffuse (const SGCOLOR &aRGBColor)
 
bool SetSpecular (float aRVal, float aGVal, float aBVal)
 
bool SetSpecular (const SGCOLOR *aRGBColor)
 
bool SetSpecular (const SGCOLOR &aRGBColor)
 
bool SetAmbient (float aRVal, float aGVal, float aBVal)
 
bool SetAmbient (const SGCOLOR *aRGBColor)
 
bool SetAmbient (const SGCOLOR &aRGBColor)
 
SGNODEFindNode (const char *aNodeName, const SGNODE *aCaller) override
 Function FindNode searches the tree of linked nodes and returns a reference to the first node found with the given name. More...
 
bool AddRefNode (SGNODE *aNode) override
 
bool AddChildNode (SGNODE *aNode) override
 
void ReNameNodes (void) override
 Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations. More...
 
bool WriteVRML (std::ostream &aFile, bool aReuseFlag) override
 Function WriteVRML writes this node's data to a VRML file; this includes all data of child and referenced nodes. More...
 
bool WriteCache (std::ostream &aFile, SGNODE *parentNode) override
 Function WriteCache write's this node's data to a binary cache file; the data includes all data of children and references to children. More...
 
bool ReadCache (std::istream &aFile, SGNODE *parentNode) override
 Function ReadCache Reads binary format data from a cache file. More...
 
void addNodeRef (SGNODE *aNode)
 Function addNodeRef adds a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (const SGNODE *aNode)
 Function delNodeRef removes a pointer to a node which references, but does not own, this node. More...
 
bool isWritten (void)
 Function IsWritten returns true if the object had already been written to a cache file or VRML file; for internal use only. More...
 
S3D::SGTYPES GetNodeType (void) const
 Function GetNodeType returns the type of this node instance. More...
 
SGNODEGetParent (void) const
 Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
bool SwapParent (SGNODE *aNewParent)
 Function SwapParent swaps the ownership with the given parent. More...
 
const char * GetName (void)
 
void SetName (const char *aName)
 
const char * GetNodeTypeName (S3D::SGTYPES aNodeType) const
 
void AssociateWrapper (SGNODE **aWrapperRef)
 Function AssociateWrapper associates this object with a handle to itself; this handle is typically held by an IFSG* wrapper and the pointer which it refers to is set to NULL upon destruction of this object. More...
 
void DisassociateWrapper (SGNODE **aWrapperRef)
 Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object. More...
 
void ResetNodeIndex (void)
 Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations. More...
 

Public Attributes

float shininess
 
float transparency
 
SGCOLOR ambient
 
SGCOLOR diffuse
 
SGCOLOR emissive
 
SGCOLOR specular
 

Protected Attributes

std::list< SGNODE * > m_BackPointers
 
SGNODEm_Parent
 
S3D::SGTYPES m_SGtype
 
std::string m_Name
 
bool m_written
 

Detailed Description

Definition at line 34 of file sg_appearance.h.

Constructor & Destructor Documentation

SGAPPEARANCE::SGAPPEARANCE ( SGNODE aParent)

Definition at line 32 of file sg_appearance.cpp.

References SGNODE::AddChildNode(), ambient, diffuse, SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::m_SGtype, SGCOLOR::SetColor(), S3D::SGTYPE_APPEARANCE, S3D::SGTYPE_SHAPE, shininess, and transparency.

32  : SGNODE( aParent)
33 {
35 
36  // defaults in accord with VRML2.0 spec
37  ambient.SetColor( 0.05317, 0.17879, 0.01804 );
38  shininess = 0.2;
39  transparency = 0.0;
40  diffuse.SetColor( 0.8, 0.8, 0.8 );
41 
42  if( NULL != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
43  {
44  m_Parent = NULL;
45 
46 #ifdef DEBUG
47  std::ostringstream ostr;
48  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
49  ostr << " * [BUG] inappropriate parent to SGAPPEARANCE (type ";
50  ostr << aParent->GetNodeType() << ")";
51  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
52 #endif
53  }
54  else if( NULL != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
55  {
56  m_Parent->AddChildNode( this );
57  }
58 
59  return;
60 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
SGNODE * m_Parent
Definition: sg_node.h:83
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
SGCOLOR ambient
Definition: sg_appearance.h:39
float transparency
Definition: sg_appearance.h:38
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
virtual bool AddChildNode(SGNODE *aNode)=0
SGAPPEARANCE::~SGAPPEARANCE ( )
virtual

Definition at line 63 of file sg_appearance.cpp.

64 {
65  return;
66 }

Member Function Documentation

bool SGAPPEARANCE::AddChildNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 269 of file sg_appearance.cpp.

270 {
271  #ifdef DEBUG
272  std::ostringstream ostr;
273  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
274  ostr << " * [BUG] this node does not accept children or refs";
275  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
276  #endif
277 
278  return false;
279 }
void SGNODE::addNodeRef ( SGNODE aNode)
inherited

Function addNodeRef adds a pointer to a node which references, but does not own, this node.

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

References SGNODE::m_BackPointers.

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

177 {
178  if( NULL == aNode )
179  return;
180 
181  std::list< SGNODE* >::iterator np =
182  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
183 
184  if( np != m_BackPointers.end() )
185  return;
186 
187  m_BackPointers.push_back( aNode );
188  return;
189 }
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
bool SGAPPEARANCE::AddRefNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 256 of file sg_appearance.cpp.

257 {
258  #ifdef DEBUG
259  std::ostringstream ostr;
260  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
261  ostr << " * [BUG] this node does not accept children or refs";
262  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
263  #endif
264 
265  return false;
266 }
void SGNODE::AssociateWrapper ( SGNODE **  aWrapperRef)
inherited

Function AssociateWrapper associates this object with a handle to itself; this 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 219 of file sg_node.cpp.

References SGNODE::m_Association.

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

220 {
221  if( NULL == aWrapperRef )
222  {
223  #ifdef DEBUG
224  std::ostringstream ostr;
225  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
226  ostr << " * [BUG] NULL handle";
227  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
228  #endif
229 
230  return;
231  }
232 
233  if( *aWrapperRef != this )
234  {
235  #ifdef DEBUG
236  std::ostringstream ostr;
237  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
238  ostr << " * [BUG] handle value does not match this object's pointer";
239  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
240  #endif
241 
242  return;
243  }
244 
245  // if there is an existing association then break it and emit a warning
246  // just in case the behavior is undesired
247  if( m_Association )
248  {
249  *m_Association = NULL;
250 
251  #ifdef DEBUG
252  std::ostringstream ostr;
253  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
254  ostr << " * [WARNING] association being broken with previous wrapper";
255  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
256  #endif
257  }
258 
259  m_Association = aWrapperRef;
260 
261  return;
262 }
SGNODE ** m_Association
Definition: sg_node.h:79
void SGNODE::delNodeRef ( const SGNODE aNode)
inherited

Function delNodeRef removes a pointer to a node which references, but does not own, this node.

Parameters
aNodeis the node holding a reference to this object

Definition at line 192 of file sg_node.cpp.

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

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

193 {
194  if( NULL == aNode )
195  return;
196 
197  std::list< SGNODE* >::iterator np =
198  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
199 
200  if( np != m_BackPointers.end() )
201  {
202  m_BackPointers.erase( np );
203  return;
204  }
205 
206  #ifdef DEBUG
207  std::ostringstream ostr;
208  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
209  ostr << " * [BUG] delNodeRef() did not find its target\n";
210  ostr << " * This Node Type: " << m_SGtype << ", Referenced node type: ";
211  ostr << aNode->GetNodeType() << "\n";
212  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
213  #endif
214 
215  return;
216 }
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
void SGNODE::DisassociateWrapper ( SGNODE **  aWrapperRef)
inherited

Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object.

Definition at line 264 of file sg_node.cpp.

References SGNODE::GetName(), SGNODE::m_Association, SGNODE::m_SGtype, and node_names.

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

265 {
266  if( !m_Association )
267  return;
268 
269  if( !aWrapperRef )
270  {
271  #ifdef DEBUG
272  std::ostringstream ostr;
273  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
274  ostr << " * [BUG] invalid handle value aWrapperRef";
275  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
276  #endif
277 
278  return;
279  }
280 
281  if( *aWrapperRef != *m_Association || aWrapperRef != m_Association )
282  {
283  #ifdef DEBUG
284  std::ostringstream ostr;
285  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
286  ostr << " * [BUG] *aWrapperRef (" << *aWrapperRef;
287  ostr << ") does not match *m_Association (" << *m_Association << ") in type ";
288  ostr << node_names[ m_SGtype] << "\n";
289  ostr << " * [INFO] OR aWrapperRef(" << aWrapperRef << ") != m_Association(";
290  ostr << m_Association << ")\n";
291  ostr << " * [INFO] node name: " << GetName();
292  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
293  #endif
294 
295  return;
296  }
297 
298  m_Association = NULL;
299 
300  return;
301 }
SGNODE ** m_Association
Definition: sg_node.h:79
const char * GetName(void)
Definition: sg_node.cpp:150
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
SGNODE * SGAPPEARANCE::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtual

Function FindNode searches the tree of linked nodes and returns 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 218 of file sg_appearance.cpp.

References SGNODE::m_Name.

Referenced by SGSHAPE::FindNode().

219 {
220  if( NULL == aNodeName || 0 == aNodeName[0] )
221  return NULL;
222 
223  if( !m_Name.compare( aNodeName ) )
224  return this;
225 
226  return NULL;
227 }
std::string m_Name
Definition: sg_node.h:85
const char * SGNODE::GetNodeTypeName ( S3D::SGTYPES  aNodeType) const
inherited

Definition at line 170 of file sg_node.cpp.

References node_names.

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

171 {
172  return node_names[aNodeType].c_str();
173 }
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
SGNODE * SGNODE::GetParent ( void  ) const
inherited
bool SGNODE::isWritten ( void  )
inlineinherited

Function IsWritten returns true if the object had already been written to a cache file or VRML file; for internal use only.

Definition at line 130 of file sg_node.h.

References SGNODE::m_written.

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

131  {
132  return m_written;
133  }
bool m_written
Definition: sg_node.h:86
bool SGAPPEARANCE::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtual

Function ReadCache 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 439 of file sg_appearance.cpp.

References ambient, diffuse, emissive, S3D::ReadColor(), shininess, specular, and transparency.

Referenced by SGSHAPE::ReadCache().

440 {
441  S3D::ReadColor( aFile, ambient );
442  aFile.read( (char*)&shininess, sizeof(shininess) );
443  aFile.read( (char*)&transparency, sizeof(transparency) );
444  S3D::ReadColor( aFile, diffuse );
445  S3D::ReadColor( aFile, emissive );
446  S3D::ReadColor( aFile, specular );
447 
448  if( aFile.fail() )
449  return false;
450 
451  return true;
452 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
bool ReadColor(std::istream &aFile, SGCOLOR &aColor)
Definition: sg_helpers.cpp:324
SGCOLOR emissive
Definition: sg_appearance.h:41
SGCOLOR ambient
Definition: sg_appearance.h:39
float transparency
Definition: sg_appearance.h:38
SGCOLOR specular
Definition: sg_appearance.h:42
void SGAPPEARANCE::ReNameNodes ( void  )
overridevirtual

Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations.

Implements SGNODE.

Definition at line 282 of file sg_appearance.cpp.

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

Referenced by SGSHAPE::ReNameNodes().

283 {
284  m_written = false;
285 
286  // rename this node
287  m_Name.clear();
288  GetName();
289 }
const char * GetName(void)
Definition: sg_node.cpp:150
bool m_written
Definition: sg_node.h:86
std::string m_Name
Definition: sg_node.h:85
void SGNODE::ResetNodeIndex ( void  )
inherited

Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations.

Definition at line 304 of file sg_node.cpp.

References node_counts, and S3D::SGTYPE_END.

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

305 {
306  for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
307  node_counts[i] = 1;
308 
309  return;
310 }
static unsigned int node_counts[S3D::SGTYPE_END]
Definition: sg_node.cpp:48
bool SGAPPEARANCE::SetAmbient ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 188 of file sg_appearance.cpp.

References ambient, and SGCOLOR::SetColor().

189 {
190  return ambient.SetColor( aRVal, aGVal, aBVal );
191 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR ambient
Definition: sg_appearance.h:39
bool SGAPPEARANCE::SetAmbient ( const SGCOLOR aRGBColor)

Definition at line 194 of file sg_appearance.cpp.

References ambient, and SGCOLOR::SetColor().

195 {
196  if( NULL == aRGBColor )
197  {
198  #ifdef DEBUG
199  std::ostringstream ostr;
200  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
201  ostr << " * [BUG] NULL pointer passed for aRGBColor";
202  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
203  #endif
204 
205  return false;
206  }
207 
208  return ambient.SetColor( aRGBColor );
209 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR ambient
Definition: sg_appearance.h:39
bool SGAPPEARANCE::SetAmbient ( const SGCOLOR aRGBColor)

Definition at line 212 of file sg_appearance.cpp.

References ambient, and SGCOLOR::SetColor().

213 {
214  return ambient.SetColor( aRGBColor );
215 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR ambient
Definition: sg_appearance.h:39
bool SGAPPEARANCE::SetDiffuse ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 129 of file sg_appearance.cpp.

References diffuse, and SGCOLOR::SetColor().

130 {
131  return diffuse.SetColor( aRVal, aGVal, aBVal );
132 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
bool SGAPPEARANCE::SetDiffuse ( const SGCOLOR aRGBColor)

Definition at line 135 of file sg_appearance.cpp.

References diffuse, and SGCOLOR::SetColor().

136 {
137  if( NULL == aRGBColor )
138  {
139  #ifdef DEBUG
140  std::ostringstream ostr;
141  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
142  ostr << " * [BUG] NULL pointer passed for aRGBColor";
143  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
144  #endif
145 
146  return false;
147  }
148 
149  return diffuse.SetColor( aRGBColor );
150 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
bool SGAPPEARANCE::SetDiffuse ( const SGCOLOR aRGBColor)

Definition at line 153 of file sg_appearance.cpp.

References diffuse, and SGCOLOR::SetColor().

154 {
155  return diffuse.SetColor( aRGBColor );
156 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
bool SGAPPEARANCE::SetEmissive ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 99 of file sg_appearance.cpp.

References emissive, and SGCOLOR::SetColor().

100 {
101  return emissive.SetColor( aRVal, aGVal, aBVal );
102 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR emissive
Definition: sg_appearance.h:41
bool SGAPPEARANCE::SetEmissive ( const SGCOLOR aRGBColor)

Definition at line 105 of file sg_appearance.cpp.

References emissive, and SGCOLOR::SetColor().

106 {
107  if( NULL == aRGBColor )
108  {
109  #ifdef DEBUG
110  std::ostringstream ostr;
111  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
112  ostr << " * [BUG] NULL pointer passed for aRGBColor";
113  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
114  #endif
115 
116  return false;
117  }
118 
119  return emissive.SetColor( aRGBColor );
120 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR emissive
Definition: sg_appearance.h:41
bool SGAPPEARANCE::SetEmissive ( const SGCOLOR aRGBColor)

Definition at line 123 of file sg_appearance.cpp.

References emissive, and SGCOLOR::SetColor().

124 {
125  return emissive.SetColor( aRGBColor );
126 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR emissive
Definition: sg_appearance.h:41
void SGNODE::SetName ( const char *  aName)
inherited

Definition at line 159 of file sg_node.cpp.

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

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

160 {
161  if( NULL == aName || 0 == aName[0] )
163  else
164  m_Name = aName;
165 
166  return;
167 }
std::string m_Name
Definition: sg_node.h:85
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
static void getNodeName(S3D::SGTYPES nodeType, std::string &aName)
Definition: sg_node.cpp:57
bool SGAPPEARANCE::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtual

Function SetParent sets 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 69 of file sg_appearance.cpp.

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

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

70 {
71  if( NULL != m_Parent )
72  {
73  if( aParent == m_Parent )
74  return true;
75 
76  // handle the change in parents
77  if( notify )
78  m_Parent->unlinkChildNode( this );
79 
80  m_Parent = NULL;
81 
82  if( NULL == aParent )
83  return true;
84  }
85 
86  // only a SGSHAPE may be parent to a SGAPPEARANCE
87  if( NULL != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
88  return false;
89 
90  m_Parent = aParent;
91 
92  if( m_Parent )
93  m_Parent->AddChildNode( this );
94 
95  return true;
96 }
SGNODE * m_Parent
Definition: sg_node.h:83
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
virtual bool AddChildNode(SGNODE *aNode)=0
bool SGAPPEARANCE::SetSpecular ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 159 of file sg_appearance.cpp.

References SGCOLOR::SetColor(), and specular.

160 {
161  return specular.SetColor( aRVal, aGVal, aBVal );
162 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR specular
Definition: sg_appearance.h:42
bool SGAPPEARANCE::SetSpecular ( const SGCOLOR aRGBColor)

Definition at line 165 of file sg_appearance.cpp.

References SGCOLOR::SetColor(), and specular.

166 {
167  if( NULL == aRGBColor )
168  {
169  #ifdef DEBUG
170  std::ostringstream ostr;
171  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
172  ostr << " * [BUG] NULL pointer passed for aRGBColor";
173  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
174  #endif
175 
176  return false;
177  }
178 
179  return specular.SetColor( aRGBColor );
180 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR specular
Definition: sg_appearance.h:42
bool SGAPPEARANCE::SetSpecular ( const SGCOLOR aRGBColor)

Definition at line 182 of file sg_appearance.cpp.

References SGCOLOR::SetColor(), and specular.

183 {
184  return specular.SetColor( aRGBColor );
185 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:104
SGCOLOR specular
Definition: sg_appearance.h:42
bool SGNODE::SwapParent ( SGNODE aNewParent)
inherited

Function SwapParent swaps the ownership with the given parent.

This operation may be required when reordering nodes for optimization.

Parameters
aNewParent[in] will become the new parent to the object; it must be the same type as the parent of this instance.

Definition at line 120 of file sg_node.cpp.

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

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

121 {
122  if( aNewParent == m_Parent )
123  return true;
124 
125  if( NULL == aNewParent )
126  return false;
127 
128  if( NULL == m_Parent )
129  {
130  if( aNewParent->AddChildNode( this ) )
131  return true;
132 
133  return false;
134  }
135 
136  if( aNewParent->GetNodeType() != m_Parent->GetNodeType() )
137  return false;
138 
139  SGNODE* oldParent = m_Parent;
140  m_Parent->unlinkChildNode( this );
141  m_Parent = NULL;
142  aNewParent->unlinkRefNode( this );
143  aNewParent->AddChildNode( this );
144  oldParent->AddRefNode( this );
145 
146  return true;
147 }
virtual bool AddRefNode(SGNODE *aNode)=0
SGNODE * m_Parent
Definition: sg_node.h:83
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
virtual void unlinkRefNode(const SGNODE *aNode)=0
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
virtual bool AddChildNode(SGNODE *aNode)=0
void SGAPPEARANCE::unlinkChildNode ( const SGNODE aNode)
overridevirtual

Function unlinkChild removes references to an owned child; it 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 230 of file sg_appearance.cpp.

231 {
232  #ifdef DEBUG
233  std::ostringstream ostr;
234  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
235  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
236  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
237  #endif
238 
239  return;
240 }
void SGAPPEARANCE::unlinkRefNode ( const SGNODE aNode)
overridevirtual

Function unlinkRef removes pointers to a referenced node; it 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 243 of file sg_appearance.cpp.

244 {
245  #ifdef DEBUG
246  std::ostringstream ostr;
247  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
248  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
249  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
250  #endif
251 
252  return;
253 }
bool SGAPPEARANCE::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtual

Function WriteCache write's 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 369 of file sg_appearance.cpp.

References ambient, diffuse, emissive, SGNODE::GetName(), SGNODE::GetParent(), SGNODE::m_Parent, SGNODE::m_written, shininess, specular, transparency, SGNODE::WriteCache(), and S3D::WriteColor().

Referenced by SGSHAPE::WriteCache().

370 {
371  if( NULL == parentNode )
372  {
373  if( NULL == m_Parent )
374  {
375  #ifdef DEBUG
376  std::ostringstream ostr;
377  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
378  ostr << " * [BUG] corrupt data; m_aParent is NULL";
379  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
380  #endif
381 
382  return false;
383  }
384 
385  SGNODE* np = m_Parent;
386 
387  while( NULL != np->GetParent() )
388  np = np->GetParent();
389 
390  if( np->WriteCache( aFile, NULL ) )
391  {
392  m_written = true;
393  return true;
394  }
395 
396  return false;
397  }
398 
399  if( parentNode != m_Parent )
400  {
401  #ifdef DEBUG
402  std::ostringstream ostr;
403  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
404  ostr << " * [BUG] corrupt data; parentNode != m_aParent";
405  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
406  #endif
407 
408  return false;
409  }
410 
411  if( !aFile.good() )
412  {
413  #ifdef DEBUG
414  std::ostringstream ostr;
415  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
416  ostr << " * [INFO] bad stream";
417  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
418  #endif
419 
420  return false;
421  }
422 
423  aFile << "[" << GetName() << "]";
424  S3D::WriteColor( aFile, ambient );
425  aFile.write( (char*)&shininess, sizeof(shininess) );
426  aFile.write( (char*)&transparency, sizeof(transparency) );
427  S3D::WriteColor( aFile, diffuse );
428  S3D::WriteColor( aFile, emissive );
429  S3D::WriteColor( aFile, specular );
430 
431  if( aFile.fail() )
432  return false;
433 
434  m_written = true;
435  return true;
436 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
SGNODE * m_Parent
Definition: sg_node.h:83
bool WriteColor(std::ostream &aFile, const SGCOLOR &aColor)
Definition: sg_helpers.cpp:193
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
SGCOLOR emissive
Definition: sg_appearance.h:41
const char * GetName(void)
Definition: sg_node.cpp:150
SGCOLOR ambient
Definition: sg_appearance.h:39
bool m_written
Definition: sg_node.h:86
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
float transparency
Definition: sg_appearance.h:38
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
SGCOLOR specular
Definition: sg_appearance.h:42
bool SGAPPEARANCE::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtual

Function WriteVRML writes this node's data to a VRML file; this includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 292 of file sg_appearance.cpp.

References ambient, diffuse, emissive, S3D::FormatFloat(), SGCOLOR::GetColor(), SGNODE::GetName(), SGNODE::m_written, shininess, specular, and transparency.

Referenced by SGSHAPE::WriteVRML().

293 {
294  if( aReuseFlag )
295  {
296  if( !m_written )
297  {
298  aFile << " appearance DEF " << GetName() << " Appearance {\n";
299  m_written = true;
300  }
301  else
302  {
303  aFile << " appearance USE " << GetName() << "\n";
304  return true;
305  }
306  }
307  else
308  {
309  aFile << " appearance Appearance {\n";
310  }
311 
312  aFile << " material Material {\n";
313 
314  std::string tmp;
315  float ambr, ambg, ambb;
316  ambient.GetColor( ambr, ambg, ambb );
317  float amb = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
318  diffuse.GetColor( ambr, ambg, ambb );
319  float den = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
320 
321  if( den < 0.004 )
322  den = 0.004;
323 
324  amb /= den;
325 
326  if( amb > 1.0 )
327  amb = 1.0;
328 
329  S3D::FormatFloat( tmp, amb );
330  aFile << " ambientIntensity " << tmp << "\n";
331 
332  float red, green, blue;
333  diffuse.GetColor( red, green, blue );
334  S3D::FormatFloat( tmp, red );
335  aFile << " diffuseColor " << tmp << " ";
336  S3D::FormatFloat( tmp, green );
337  aFile << tmp << " ";
338  S3D::FormatFloat( tmp, blue);
339  aFile << tmp << "\n";
340 
341  emissive.GetColor( red, green, blue );
342  S3D::FormatFloat( tmp, red );
343  aFile << " emissiveColor " << tmp << " ";
344  S3D::FormatFloat( tmp, green );
345  aFile << tmp << " ";
346  S3D::FormatFloat( tmp, blue);
347  aFile << tmp << "\n";
348 
349  S3D::FormatFloat( tmp, shininess );
350  aFile << " shininess " << tmp << "\n";
351 
352  specular.GetColor( red, green, blue );
353  S3D::FormatFloat( tmp, red );
354  aFile << " specularColor " << tmp << " ";
355  S3D::FormatFloat( tmp, green );
356  aFile << tmp << " ";
357  S3D::FormatFloat( tmp, blue);
358  aFile << tmp << "\n";
359 
361  aFile << " transparency " << tmp << "\n";
362 
363  aFile << "} }\n";
364 
365  return true;
366 }
SGCOLOR diffuse
Definition: sg_appearance.h:40
SGCOLOR emissive
Definition: sg_appearance.h:41
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
const char * GetName(void)
Definition: sg_node.cpp:150
SGCOLOR ambient
Definition: sg_appearance.h:39
bool m_written
Definition: sg_node.h:86
float transparency
Definition: sg_appearance.h:38
SGCOLOR specular
Definition: sg_appearance.h:42
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const
Definition: sg_base.cpp:65

Member Data Documentation

SGCOLOR SGAPPEARANCE::ambient
SGCOLOR SGAPPEARANCE::diffuse
SGCOLOR SGAPPEARANCE::emissive

Definition at line 41 of file sg_appearance.h.

Referenced by formatMaterial(), ReadCache(), SetEmissive(), WriteCache(), and WriteVRML().

std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited
float SGAPPEARANCE::shininess
SGCOLOR SGAPPEARANCE::specular
float SGAPPEARANCE::transparency

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