use shared_ptr in shell visitor. add dump() code. hide debug cout.

felipesanches-svg
Don Bright 2012-02-13 18:43:38 -06:00
parent a76d5b02bd
commit 319364b597
6 changed files with 107 additions and 46 deletions

View File

@ -77,28 +77,28 @@ DxfData *CGAL_Nef_polyhedron::convertToDxfData() const
return dxfdata;
}
// moved here to reduce compile size/time of CGAL_Nef_polyhedron.cc
// moved here to reduce compile size/time of compiling CGAL_Nef_polyhedron.cc
std::string CGAL_Nef_polyhedron::dump_p2() const
{
std::stringstream out;
CGAL_Nef_polyhedron2::Explorer explorer = this->p2->explorer();
CGAL_Nef_polyhedron2::Explorer::Vertex_const_iterator i;
out << "CGAL_Nef_polyhedron::p2 vertices";
out << "CGAL_Nef_polyhedron::p2 Vertices";
for (i = explorer.vertices_begin(); i != explorer.vertices_end(); ++i) {
if ( explorer.is_standard( i ) ) {
CGAL_Nef_polyhedron2::Explorer::Point point = explorer.point( i );
out << "\n Standard vertex x y: "
out << "\n Point x y: "
<< CGAL::to_double(point.x()) << " "
<< CGAL::to_double(point.y());
} else {
CGAL_Nef_polyhedron2::Explorer::Ray ray = explorer.ray( i );
CGAL_Nef_polyhedron2::Explorer::Point point = ray.point( 0 );
out << "\n Ray x y dx dy: "
<< CGAL::to_double(point.x()) << " " << CGAL::to_double(point.y())
<< CGAL::to_double(ray.direction().dx()) << " " << CGAL::to_double(ray.direction().dy()) << "\n";
<< CGAL::to_double(point.x()) << " " << CGAL::to_double(point.y()) << " "
<< CGAL::to_double(ray.direction().dx()) << " " << CGAL::to_double(ray.direction().dy());
}
}
out << "\nCGAL_Nef_polyhedron::p2 vertices end";
out << "\nCGAL_Nef_polyhedron::p2 Vertices end";
return out.str();
}

View File

@ -22,37 +22,42 @@
class NefShellVisitor_for_cut {
public:
std::stringstream out;
CGAL_Nef_polyhedron2 tmpnef;
CGAL_Nef_polyhedron2 nefpoly2d;
shared_ptr<CGAL_Nef_polyhedron2> tmpnef;
shared_ptr<CGAL_Nef_polyhedron2> nefpoly2d;
CGAL_Nef_polyhedron2::Boundary boundary;
NefShellVisitor_for_cut()
{ boundary = CGAL_Nef_polyhedron2::INCLUDED; }
{
nefpoly2d.reset( new CGAL_Nef_polyhedron2() );
boundary = CGAL_Nef_polyhedron2::INCLUDED;
}
std::string dump()
{ return out.str(); }
{
return out.str();
}
void visit( CGAL_Nef_polyhedron3::Vertex_const_handle ) {}
void visit( CGAL_Nef_polyhedron3::Halfedge_const_handle ) {}
void visit( CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {}
void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {}
void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {}
void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) {
// this method is fed each 'facet' of the Nef_polyhedron3 that's been intersected
// with the flat x-y plane.
// This method is fed each 'facet' of the Nef_polyhedron3 that's been intersected
// with the flat x-y plane. I.e. it's fed a bunch of flat polygons.
//
// So, we assume that all z coordinates are 0.
//
// Now. CGAL_Nef_poly3d objects have two 'half facets' for every flat shape.
// i.e. on a cube, there are 12 'half facets', 6 pointing 'in' and 6 'out'.
// Now. CGAL_Nef_poly3d objects have two 'half facets'.
// On a flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'.
// We only use the 'down' facets here. Why? Because otherwise you get a double-set of vertices!
// Now, we only want the vertexes--- so we only don't need both 'up' and 'down' facets.
// What do we do? Just skip the 'down' facets!
//
// Also note, 'up' facets list vertexs in CounterClockwise Order, and 'down' facets list vertexs
// By the way, 'up' facets list vertexs in CounterClockwise Order, and 'down' facets list vertexs
// in Clockwise order. (or is it the other way round?).
CGAL::Direction_3<CGAL_Kernel3> up(0,0,1);
CGAL::Plane_3<CGAL_Kernel3> plane = hfacet->plane();
out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n";
if ( plane.orthogonal_direction() != up ) {
out << "direction == down. skipping\n";
// out << "direction == down. skipping";
return;
}
@ -77,13 +82,13 @@ public:
//out << " add xyz " << x << " "<< y << " " <<z << endl;
j = j->next();
} while ( j != first_halfedge );
tmpnef = CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary );
tmpnef.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) );
if ( numcontours == 0 ) {
out << " contour is a body. joining." << contour.size() << " points.\n" ;
nefpoly2d = nefpoly2d.join( tmpnef );
//out << " contour is a body. joining. " << contour.size() << " points.\n" ;
*nefpoly2d += *tmpnef;
} else {
out << " contour is a hole. intersecting." << contour.size() << "points.\n";
nefpoly2d = nefpoly2d.intersection( tmpnef );
//out << " contour is a hole. intersecting. " << contour.size() << "points.\n";
*nefpoly2d *= *tmpnef;
}
numcontours++;
} // next facet cycle
@ -95,8 +100,6 @@ PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator)
{
}
#include <iostream>
PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
{
// Before projecting, union all children
@ -112,14 +115,14 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
if (sum.empty()) return NULL;
PolySet *ps = new PolySet();
PolySet *ps3 = NULL;
DxfData *dxf = NULL;
CGAL_Nef_polyhedron np;
ps->convexity = node.convexity;
ps->is2d = true;
// In cut mode, the model is intersected by a large but very thin box living on the
// XY plane.
if (node.cut_mode)
{
//----------------------------
CGAL_Nef_polyhedron3::Plane_3 plane = CGAL_Nef_polyhedron3::Plane_3( 0,0,1,0 );
*sum.p3 = sum.p3->intersection( plane, CGAL_Nef_polyhedron3::PLANE_ONLY);
@ -133,26 +136,26 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
sum.p3->visit_shell_objects( sface_handle , shell_visitor );
}
}
// std::cout << "shell visitor\n" << shell_visitor.dump() << "\n";
std::cout << "shell visitor\n" << shell_visitor.dump() << "\n";
//----------------------------
/* if (!sum.p3->is_simple()) {
/*if (!sum.p3->is_simple()) {
PRINT("WARNING: Body of projection(cut = true) isn't valid 2-manifold! Modify your design..");
goto cant_project_non_simple_polyhedron;
}*/
CGAL_Nef_polyhedron flat_nef_poly;
*(flat_nef_poly.p2) = shell_visitor.nefpoly2d;
flat_nef_poly.dim = 2;
PolySet *ps3 = flat_nef_poly.convertToPolyset();
np.p2 = shell_visitor.nefpoly2d;
// std::cout << np.dump_p2() << "\n";
np.dim = 2;
ps3 = np.convertToPolyset();
// std::cout << "----------\n" << ps3->dump() << "\n";
if (!ps3) return NULL;
// Extract polygons in the XY plane, ignoring all other polygons
// FIXME: If the polyhedron is really thin, there might be unwanted polygons
// in the XY plane, causing the resulting 2D polygon to be self-intersection
// and cause a crash in CGALEvaluator::PolyReducer. The right solution is to
// filter these polygons here. kintel 20120203.
// FIXME: If the polyhedron is really thin, there might be unwanted polygons
// in the XY plane, causing the resulting 2D polygon to be self-intersection
// and cause a crash in CGALEvaluator::PolyReducer. The right solution is to
// filter these polygons here. kintel 20120203.
Grid2d<int> conversion_grid(GRID_COARSE);
for (size_t i = 0; i < ps3->polygons.size(); i++) {
for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
@ -175,6 +178,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
next_ps3_polygon_cut_mode:;
}
delete ps3;
}
// In projection mode all the triangles are projected manually into the XY plane
else
@ -184,9 +188,8 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
goto cant_project_non_simple_polyhedron;
}
PolySet *ps3 = sum.convertToPolyset();
ps3 = sum.convertToPolyset();
if (!ps3) return NULL;
CGAL_Nef_polyhedron np;
for (size_t i = 0; i < ps3->polygons.size(); i++)
{
int min_x_p = -1;
@ -233,12 +236,12 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
(*np.p2) += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);
}
}
delete ps3;
DxfData *dxf = np.convertToDxfData();
dxf_tesselate(ps, *dxf, 0, true, false, 0);
dxf_border_to_ps(ps, *dxf);
delete dxf;
}
delete ps3;
dxf = np.convertToDxfData();
dxf_tesselate(ps, *dxf, 0, true, false, 0);
dxf_border_to_ps(ps, *dxf);
delete dxf;
cant_project_non_simple_polyhedron:
return ps;

View File

@ -38,6 +38,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <sstream>
#include <QDir>
#include "value.h"
@ -555,3 +556,27 @@ int DxfData::addPoint(double x, double y)
return this->points.size()-1;
}
std::string DxfData::dump() const
{
std::stringstream out;
out << "DxfData"
<< "\n num points: " << points.size()
<< "\n num paths: " << paths.size()
<< "\n num dims: " << dims.size()
<< "\n points: ";
for ( size_t k = 0 ; k < points.size() ; k++ ) {
out << "\n x y: " << points[k].transpose();
}
out << "\n paths: ";
for ( size_t i = 0; i < paths.size(); i++ ) {
out << "\n path:" << i
<< "\n is_closed: " << paths[i].is_closed
<< "\n is_inner: " << paths[i].is_inner ;
DxfData::Path path = paths[i];
for ( size_t j = 0; j < path.indices.size(); j++ ) {
out << "\n index[" << j << "]==" << path.indices[j];
}
}
out << "\nDxfData end";
return out.str();
}

View File

@ -44,6 +44,7 @@ public:
int addPoint(double x, double y);
void fixup_path_direction();
std::string dump() const;
};
#endif

View File

@ -48,6 +48,36 @@ PolySet::~PolySet()
{
}
std::string PolySet::dump() const
{
std::stringstream out;
out << "PolySet:"
<< "\n dimensions:" << std::string( this->is2d ? "2" : "3" )
<< "\n convexity:" << this->convexity
<< "\n num polygons: " << polygons.size()
<< "\n num borders: " << borders.size()
<< "\n polygons data:";
for (size_t i = 0; i < polygons.size(); i++) {
out << "\n polygon begin:";
const Polygon *poly = &polygons[i];
for (size_t j = 0; j < poly->size(); j++) {
Vector3d v = poly->at(j);
out << "\n vertex:" << v.transpose();
}
}
out << "\n borders data:";
for (size_t i = 0; i < borders.size(); i++) {
out << "\n border polygon begin:";
const Polygon *poly = &borders[i];
for (size_t j = 0; j < poly->size(); j++) {
Vector3d v = poly->at(j);
out << "\n vertex:" << v.transpose();
}
}
out << "\nPolySet end";
return out.str();
}
void PolySet::append_poly()
{
polygons.push_back(Polygon());

View File

@ -5,6 +5,7 @@
#include "grid.h"
#include "linalg.h"
#include <vector>
#include <string>
class PolySet
{
@ -40,6 +41,7 @@ public:
void render_surface(csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo = NULL) const;
void render_edges(csgmode_e csgmode) const;
std::string dump() const;
};
#endif