KiCad PCB EDA Suite
SGAPPEARANCE Class Reference

Defines the generic material appearance of a scenegraph object. More...

#include <sg_appearance.h>

Inheritance diagram for SGAPPEARANCE:
SGNODE

Public Member Functions

void unlinkChildNode (const SGNODE *aNode) noexcept override
 Remove references to an owned child. More...
 
void unlinkRefNode (const SGNODE *aNode) noexcept override
 Remove pointers to a referenced node. More...
 
 SGAPPEARANCE (SGNODE *aParent)
 
virtual ~SGAPPEARANCE ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set 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) 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 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

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

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

Defines the generic material appearance of a scenegraph object.

Definition at line 37 of file sg_appearance.h.

Constructor & Destructor Documentation

◆ SGAPPEARANCE()

SGAPPEARANCE::SGAPPEARANCE ( SGNODE aParent)

Definition at line 34 of file sg_appearance.cpp.

34  : SGNODE( aParent )
35 {
37 
38  // defaults in accord with VRML2.0 spec
39  ambient.SetColor( 0.05317f, 0.17879f, 0.01804f );
40  shininess = 0.2f;
41  transparency = 0.0f;
42  diffuse.SetColor( 0.8f, 0.8f, 0.8f );
43 
44  if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
45  {
46  m_Parent = nullptr;
47 
48  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] inappropriate parent to SGAPPEARANCE (type %s )",
49  __FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
50  }
51  else if( nullptr != aParent && S3D::SGTYPE_SHAPE == aParent->GetNodeType() )
52  {
53  m_Parent->AddChildNode( this );
54  }
55 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76
float transparency
Definition: sg_appearance.h:75
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
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(), ambient, diffuse, SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::m_SGtype, SGCOLOR::SetColor(), S3D::SGTYPE_APPEARANCE, S3D::SGTYPE_SHAPE, shininess, and transparency.

◆ ~SGAPPEARANCE()

SGAPPEARANCE::~SGAPPEARANCE ( )
virtual

Definition at line 58 of file sg_appearance.cpp.

59 {
60 }

Member Function Documentation

◆ AddChildNode()

bool SGAPPEARANCE::AddChildNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 207 of file sg_appearance.cpp.

208 {
209  wxCHECK_MSG( aNode, false, "this node does not accept children or refs" );
210 
211  // This is redundant but it keeps gcc from generating a warning on debug builds.
212  return false;
213 }

◆ 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 SGAPPEARANCE::AddRefNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 198 of file sg_appearance.cpp.

199 {
200  wxCHECK_MSG( aNode, false, "this node does not accept children or refs" );
201 
202  // This is redundant but it keeps gcc from generating a warning on debug builds.
203  return false;
204 }

◆ 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_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().

◆ 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_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().

◆ FindNode()

SGNODE * SGAPPEARANCE::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtualnoexcept

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 172 of file sg_appearance.cpp.

173 {
174  if( nullptr == aNodeName || 0 == aNodeName[0] )
175  return nullptr;
176 
177  if( !m_Name.compare( aNodeName ) )
178  return this;
179 
180  return nullptr;
181 }
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

Referenced by SGSHAPE::FindNode().

◆ 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_NORMALS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::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_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), SGSHAPE::WriteCache(), SGNORMALS::WriteCache(), SCENEGRAPH::WriteCache(), SGCOLORS::WriteCache(), SGFACESET::WriteCache(), SGCOORDS::WriteCache(), 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 SGAPPEARANCE::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 348 of file sg_appearance.cpp.

349 {
350  S3D::ReadColor( aFile, ambient );
351  aFile.read( (char*) &shininess, sizeof( shininess ) );
352  aFile.read( (char*) &transparency, sizeof( transparency ) );
353  S3D::ReadColor( aFile, diffuse );
354  S3D::ReadColor( aFile, emissive );
355  S3D::ReadColor( aFile, specular );
356 
357  if( aFile.fail() )
358  return false;
359 
360  return true;
361 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool ReadColor(std::istream &aFile, SGCOLOR &aColor)
Definition: sg_helpers.cpp:294
SGCOLOR emissive
Definition: sg_appearance.h:78
SGCOLOR ambient
Definition: sg_appearance.h:76
float transparency
Definition: sg_appearance.h:75
SGCOLOR specular
Definition: sg_appearance.h:79

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

Referenced by SGSHAPE::ReadCache().

◆ ReNameNodes()

void SGAPPEARANCE::ReNameNodes ( void  )
overridevirtual

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

Implements SGNODE.

Definition at line 216 of file sg_appearance.cpp.

217 {
218  m_written = false;
219 
220  // rename this node
221  m_Name.clear();
222  GetName();
223 }
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 SGSHAPE::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().

◆ SetAmbient() [1/3]

bool SGAPPEARANCE::SetAmbient ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 152 of file sg_appearance.cpp.

153 {
154  return ambient.SetColor( aRVal, aGVal, aBVal );
155 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76

References ambient, and SGCOLOR::SetColor().

◆ SetAmbient() [2/3]

bool SGAPPEARANCE::SetAmbient ( const SGCOLOR aRGBColor)

Definition at line 158 of file sg_appearance.cpp.

159 {
160  wxCHECK_MSG( aRGBColor, false, "NULL pointer passed for aRGBColor" );
161 
162  return ambient.SetColor( aRGBColor );
163 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76

References ambient, and SGCOLOR::SetColor().

◆ SetAmbient() [3/3]

bool SGAPPEARANCE::SetAmbient ( const SGCOLOR aRGBColor)

Definition at line 166 of file sg_appearance.cpp.

167 {
168  return ambient.SetColor( aRGBColor );
169 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR ambient
Definition: sg_appearance.h:76

References ambient, and SGCOLOR::SetColor().

◆ SetDiffuse() [1/3]

bool SGAPPEARANCE::SetDiffuse ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 113 of file sg_appearance.cpp.

114 {
115  return diffuse.SetColor( aRVal, aGVal, aBVal );
116 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References diffuse, and SGCOLOR::SetColor().

◆ SetDiffuse() [2/3]

bool SGAPPEARANCE::SetDiffuse ( const SGCOLOR aRGBColor)

Definition at line 119 of file sg_appearance.cpp.

120 {
121  wxCHECK_MSG( aRGBColor, false, "NULL pointer passed for aRGBColor" );
122 
123  return diffuse.SetColor( aRGBColor );
124 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References diffuse, and SGCOLOR::SetColor().

◆ SetDiffuse() [3/3]

bool SGAPPEARANCE::SetDiffuse ( const SGCOLOR aRGBColor)

Definition at line 127 of file sg_appearance.cpp.

128 {
129  return diffuse.SetColor( aRGBColor );
130 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85

References diffuse, and SGCOLOR::SetColor().

◆ SetEmissive() [1/3]

bool SGAPPEARANCE::SetEmissive ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 93 of file sg_appearance.cpp.

94 {
95  return emissive.SetColor( aRVal, aGVal, aBVal );
96 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR emissive
Definition: sg_appearance.h:78

References emissive, and SGCOLOR::SetColor().

◆ SetEmissive() [2/3]

bool SGAPPEARANCE::SetEmissive ( const SGCOLOR aRGBColor)

Definition at line 99 of file sg_appearance.cpp.

100 {
101  wxCHECK_MSG( aRGBColor, false, "NULL pointer passed for aRGBColor" );
102 
103  return emissive.SetColor( aRGBColor );
104 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR emissive
Definition: sg_appearance.h:78

References emissive, and SGCOLOR::SetColor().

◆ SetEmissive() [3/3]

bool SGAPPEARANCE::SetEmissive ( const SGCOLOR aRGBColor)

Definition at line 107 of file sg_appearance.cpp.

108 {
109  return emissive.SetColor( aRGBColor );
110 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR emissive
Definition: sg_appearance.h:78

References emissive, and SGCOLOR::SetColor().

◆ 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 SGAPPEARANCE::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 63 of file sg_appearance.cpp.

64 {
65  if( nullptr != m_Parent )
66  {
67  if( aParent == m_Parent )
68  return true;
69 
70  // handle the change in parents
71  if( notify )
72  m_Parent->unlinkChildNode( this );
73 
74  m_Parent = nullptr;
75 
76  if( nullptr == aParent )
77  return true;
78  }
79 
80  // only a SGSHAPE may be parent to a SGAPPEARANCE
81  if( nullptr != aParent && S3D::SGTYPE_SHAPE != aParent->GetNodeType() )
82  return false;
83 
84  m_Parent = aParent;
85 
86  if( m_Parent )
87  m_Parent->AddChildNode( this );
88 
89  return true;
90 }
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_SHAPE, and SGNODE::unlinkChildNode().

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

◆ SetSpecular() [1/3]

bool SGAPPEARANCE::SetSpecular ( float  aRVal,
float  aGVal,
float  aBVal 
)

Definition at line 133 of file sg_appearance.cpp.

134 {
135  return specular.SetColor( aRVal, aGVal, aBVal );
136 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR specular
Definition: sg_appearance.h:79

References SGCOLOR::SetColor(), and specular.

◆ SetSpecular() [2/3]

bool SGAPPEARANCE::SetSpecular ( const SGCOLOR aRGBColor)

Definition at line 139 of file sg_appearance.cpp.

140 {
141  wxCHECK_MSG( aRGBColor, false, "NULL pointer passed for aRGBColor" );
142 
143  return specular.SetColor( aRGBColor );
144 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR specular
Definition: sg_appearance.h:79

References SGCOLOR::SetColor(), and specular.

◆ SetSpecular() [3/3]

bool SGAPPEARANCE::SetSpecular ( const SGCOLOR aRGBColor)

Definition at line 146 of file sg_appearance.cpp.

147 {
148  return specular.SetColor( aRGBColor );
149 }
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
SGCOLOR specular
Definition: sg_appearance.h:79

References SGCOLOR::SetColor(), and specular.

◆ 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 SGAPPEARANCE::unlinkChildNode ( const SGNODE aNode)
overridevirtualnoexcept

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 184 of file sg_appearance.cpp.

185 {
186  wxCHECK_MSG( aCaller, /* void */,
187  "unexpected code branch; node should have no children or refs" );
188 }

◆ unlinkRefNode()

void SGAPPEARANCE::unlinkRefNode ( const SGNODE aNode)
overridevirtualnoexcept

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 191 of file sg_appearance.cpp.

192 {
193  wxCHECK_MSG( aCaller, /* void */,
194  "unexpected code branch; node should have no children or refs" );
195 }

◆ WriteCache()

bool SGAPPEARANCE::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 303 of file sg_appearance.cpp.

304 {
305  if( nullptr == parentNode )
306  {
307  wxCHECK_MSG( m_Parent, false, "corrupt data; m_aParent is NULL" );
308 
309  SGNODE* np = m_Parent;
310 
311  while( nullptr != np->GetParent() )
312  np = np->GetParent();
313 
314  if( np->WriteCache( aFile, nullptr ) )
315  {
316  m_written = true;
317  return true;
318  }
319 
320  return false;
321  }
322 
323  wxCHECK_MSG( parentNode == m_Parent, false, "corrupt data; parentNode != m_aParent" );
324 
325  if( !aFile.good() )
326  {
327  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [INFO] bad stream", __FILE__, __FUNCTION__, __LINE__ );
328 
329  return false;
330  }
331 
332  aFile << "[" << GetName() << "]";
333  S3D::WriteColor( aFile, ambient );
334  aFile.write( (char*) &shininess, sizeof( shininess ) );
335  aFile.write( (char*) &transparency, sizeof( transparency ) );
336  S3D::WriteColor( aFile, diffuse );
337  S3D::WriteColor( aFile, emissive );
338  S3D::WriteColor( aFile, specular );
339 
340  if( aFile.fail() )
341  return false;
342 
343  m_written = true;
344  return true;
345 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
bool WriteColor(std::ostream &aFile, const SGCOLOR &aColor)
Definition: sg_helpers.cpp:180
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
SGCOLOR emissive
Definition: sg_appearance.h:78
const char * GetName(void)
Definition: sg_node.cpp:146
SGCOLOR ambient
Definition: sg_appearance.h:76
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
float transparency
Definition: sg_appearance.h:75
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.
SGCOLOR specular
Definition: sg_appearance.h:79

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

◆ WriteVRML()

bool SGAPPEARANCE::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 226 of file sg_appearance.cpp.

227 {
228  if( aReuseFlag )
229  {
230  if( !m_written )
231  {
232  aFile << " appearance DEF " << GetName() << " Appearance {\n";
233  m_written = true;
234  }
235  else
236  {
237  aFile << " appearance USE " << GetName() << "\n";
238  return true;
239  }
240  }
241  else
242  {
243  aFile << " appearance Appearance {\n";
244  }
245 
246  aFile << " material Material {\n";
247 
248  std::string tmp;
249  float ambr, ambg, ambb;
250  ambient.GetColor( ambr, ambg, ambb );
251  float amb = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
252  diffuse.GetColor( ambr, ambg, ambb );
253  float den = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
254 
255  if( den < 0.004f )
256  den = 0.004f;
257 
258  amb /= den;
259 
260  if( amb > 1.0f )
261  amb = 1.0f;
262 
263  S3D::FormatFloat( tmp, amb );
264  aFile << " ambientIntensity " << tmp << "\n";
265 
266  float red, green, blue;
267  diffuse.GetColor( red, green, blue );
268  S3D::FormatFloat( tmp, red );
269  aFile << " diffuseColor " << tmp << " ";
270  S3D::FormatFloat( tmp, green );
271  aFile << tmp << " ";
272  S3D::FormatFloat( tmp, blue);
273  aFile << tmp << "\n";
274 
275  emissive.GetColor( red, green, blue );
276  S3D::FormatFloat( tmp, red );
277  aFile << " emissiveColor " << tmp << " ";
278  S3D::FormatFloat( tmp, green );
279  aFile << tmp << " ";
280  S3D::FormatFloat( tmp, blue);
281  aFile << tmp << "\n";
282 
283  S3D::FormatFloat( tmp, shininess );
284  aFile << " shininess " << tmp << "\n";
285 
286  specular.GetColor( red, green, blue );
287  S3D::FormatFloat( tmp, red );
288  aFile << " specularColor " << tmp << " ";
289  S3D::FormatFloat( tmp, green );
290  aFile << tmp << " ";
291  S3D::FormatFloat( tmp, blue);
292  aFile << tmp << "\n";
293 
295  aFile << " transparency " << tmp << "\n";
296 
297  aFile << "} }\n";
298 
299  return true;
300 }
SGCOLOR diffuse
Definition: sg_appearance.h:77
SGCOLOR emissive
Definition: sg_appearance.h:78
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
Definition: sg_base.cpp:59
void FormatFloat(std::string &result, double value)
Definition: sg_helpers.cpp:37
const char * GetName(void)
Definition: sg_node.cpp:146
SGCOLOR ambient
Definition: sg_appearance.h:76
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
float transparency
Definition: sg_appearance.h:75
SGCOLOR specular
Definition: sg_appearance.h:79

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

Referenced by SGSHAPE::WriteVRML().

Member Data Documentation

◆ ambient

SGCOLOR SGAPPEARANCE::ambient

◆ diffuse

SGCOLOR SGAPPEARANCE::diffuse

◆ emissive

SGCOLOR SGAPPEARANCE::emissive

Definition at line 78 of file sg_appearance.h.

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

◆ 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

◆ shininess

float SGAPPEARANCE::shininess

◆ specular

SGCOLOR SGAPPEARANCE::specular

◆ transparency

float SGAPPEARANCE::transparency

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