Updated VRML exporter and fixed some VRML related bugs

This commit is contained in:
Cirilo Bernardo 2016-09-17 16:14:49 +10:00 committed by Wayne Stambaugh
parent 65821328d2
commit d3771d53ef
5 changed files with 821 additions and 307 deletions

View File

@ -131,13 +131,13 @@ class SGCOORDINDEX;
aOwnedList.push_back( (aType*)aNode ); \
aNode->SetParent( this, false ); \
} else { \
if( NULL == aNode->GetParent() ) { \
/*if( NULL == aNode->GetParent() ) { \
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; \
std::cerr << " * [BUG] object '" << aNode->GetName(); \
std::cerr << "' has no parent\n"; \
std::cerr << " * [INFO] possible copy assignment or copy constructor bug\n"; \
return false; \
} \
} */ \
aRefList.push_back( (aType*)aNode ); \
aNode->addNodeRef( this ); \
} \

File diff suppressed because it is too large Load Diff

View File

@ -340,8 +340,8 @@ static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >*
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] cannot create an outline";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] cannot create an outline";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -354,8 +354,8 @@ static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >*
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] invalid contour: no vertices";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid contour: no vertices";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -376,8 +376,8 @@ static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >*
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] cannot add segment";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] cannot add segment";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -410,8 +410,8 @@ static bool addSegment( VRML_LAYER& model, IDF_SEGMENT* seg, int icont, int iseg
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] adding a circle to an existing vertex list";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] adding a circle to an existing vertex list";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -454,8 +454,8 @@ static SCENEGRAPH* vrmlToSG( VRML_LAYER& vpcb, int idxColor, SGNODE* aParent, do
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] no vertex data";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] no vertex data";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -468,8 +468,8 @@ static SCENEGRAPH* vrmlToSG( VRML_LAYER& vpcb, int idxColor, SGNODE* aParent, do
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -574,8 +574,8 @@ static SCENEGRAPH* addOutline( IDF3_COMP_OUTLINE* outline, int idxColor, SGNODE*
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] no valid outline data";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] no valid outline data";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -614,11 +614,11 @@ static SCENEGRAPH* loadIDFOutline( const wxString& aFileName )
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] Failed to read IDF data:\n";
std::cerr << brd.GetError() << "\n\n";
std::cerr << " * [INFO] no outline for file '";
std::cerr << aFileName << "'";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] Failed to read IDF data:\n";
ostr << brd.GetError() << "\n\n";
ostr << " * [INFO] no outline for file '";
ostr << aFileName << "'";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
@ -643,10 +643,10 @@ static SCENEGRAPH* loadIDFBoard( const wxString& aFileName )
#ifdef DEBUG
do {
std::ostringstream ostr;
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] Failed to read IDF file:\n";
std::cerr << brd.GetError() << "\n\n";
std::cerr << " * [INFO] IDF file '" << aFileName.ToUTF8() << "'";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] Failed to read IDF file:\n";
ostr << brd.GetError() << "\n\n";
ostr << " * [INFO] IDF file '" << aFileName.ToUTF8() << "'";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif

View File

@ -468,7 +468,7 @@ bool VRML_LAYER::AppendCircle( double aXpos, double aYpos,
}
// adds a circle the existing list; if 'hole' is true the contour is
// adds a circle to the existing list; if 'hole' is true the contour is
// a hole. Returns true if OK.
bool VRML_LAYER::AddCircle( double aXpos, double aYpos, double aRadius,
bool aHoleFlag, bool aPlatedHole )
@ -1826,8 +1826,8 @@ bool VRML_LAYER::Get3DTriangles( std::vector< double >& aVertexList,
return false;
}
aVertexList.push_back( vp->x );
aVertexList.push_back( vp->y );
aVertexList.push_back( vp->x + offsetX );
aVertexList.push_back( vp->y + offsetY );
aVertexList.push_back( aTopZ );
}
@ -1836,8 +1836,8 @@ bool VRML_LAYER::Get3DTriangles( std::vector< double >& aVertexList,
{
vp = getVertexByIndex( ordmap[i], pholes );
aVertexList.push_back( vp->x );
aVertexList.push_back( vp->y );
aVertexList.push_back( vp->x + offsetX );
aVertexList.push_back( vp->y + offsetY );
aVertexList.push_back( aBotZ );
}
@ -1961,3 +1961,77 @@ bool VRML_LAYER::Get3DTriangles( std::vector< double >& aVertexList,
return true;
}
bool VRML_LAYER::Get2DTriangles( std::vector< double >& aVertexList,
std::vector< int > &aIndexPlane, double aHeight, bool aTopPlane )
{
aVertexList.clear();
aIndexPlane.clear();
if( ordmap.size() < 3 || outline.empty() )
return false;
VERTEX_3D* vp = getVertexByIndex( ordmap[0], pholes );
if( !vp )
return false;
size_t i;
size_t vsize = ordmap.size();
// vertices
for( i = 0; i < vsize; ++i )
{
vp = getVertexByIndex( ordmap[i], pholes );
if( !vp )
{
aVertexList.clear();
return false;
}
aVertexList.push_back( vp->x + offsetX );
aVertexList.push_back( vp->y + offsetY );
aVertexList.push_back( aHeight );
}
// create the index lists .. it is difficult to estimate the list size
// a priori so instead we use a vector to help
if( triplets.empty() )
return false;
// go through the triplet list and write out the indices based on order
std::list< TRIPLET_3D >::const_iterator tbeg = triplets.begin();
std::list< TRIPLET_3D >::const_iterator tend = triplets.end();
std::vector< int > aIndexBot;
if( aTopPlane )
{
while( tbeg != tend )
{
// top vertices
aIndexPlane.push_back( (int) tbeg->i1 );
aIndexPlane.push_back( (int) tbeg->i2 );
aIndexPlane.push_back( (int) tbeg->i3 );
++tbeg;
}
}
else
{
while( tbeg != tend )
{
// bottom vertices
aIndexPlane.push_back( (int) ( tbeg->i2 ) );
aIndexPlane.push_back( (int) ( tbeg->i1 ) );
aIndexPlane.push_back( (int) ( tbeg->i3 ) );
++tbeg;
}
}
return true;
}

View File

@ -460,7 +460,7 @@ public:
/**
* Function Get3DTriangles
* Allocates and populates the 3D vertex and index lists with
* triangular vertices which may be used for rendering.
* triangular vertices which may be used for rendering a volume
*
* @param aVertexList will store the vertices
* @param aIndexPlane will store the indices for the top + bottom planes
@ -472,6 +472,19 @@ public:
std::vector< int > &aIndexPlane, std::vector< int > &aIndexSide,
double aTopZ, double aBotZ );
/**
* Function Get2DTriangles
* Allocates and populates the 3D vertex and index lists with
* triangular vertices which may be used for rendering a plane
*
* @param aVertexList will store the vertices
* @param aIndexPlane will store the indices for the plane
* @param aHeight is the plane of the model
* @param aTopPlane is true if the plane is a top plane (false = reverse indices)
*/
bool Get2DTriangles( std::vector< double >& aVertexList,
std::vector< int > &aIndexPlane, double aHeight, bool aTopPlane );
};
#endif // VRML_LAYER_H