123{
124 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <input.obj> <h> <view>" << std::endl;
125 trace.
info() <<
"\tComputes a digital polyhedron from an OBJ file" << std::endl;
126 trace.
info() <<
"\t- input.obj: choose your favorite mesh" << std::endl;
127 trace.
info() <<
"\t- h [==1]: the digitization gridstep" << std::endl;
128 trace.
info() <<
"\t- view [==31]: display vertices(1), common edges(2), positive side f edges(4), negative side f edges (8), faces(16)" << std::endl;
129 string filename = examplesPath + "samples/lion.obj";
130 std::string fn = argc > 1 ? argv[ 1 ] : filename;
131 double h = argc > 2 ? atof( argv[ 2 ] ) : 1.0;
132 int view = argc > 3 ? atoi( argv[ 3 ] ) : 31;
133
134 std::ifstream input( fn.c_str() );
137 if ( ! ok )
138 {
139 trace.
error() <<
"Unable to read obj file : " << fn << std::endl;
140 return 1;
141 }
142
143 QApplication application(argc,argv);
145 MViewer viewer;
146 viewer.setWindowTitle("standardDigitalPolyhedronBuilder3D");
148
149 Point lo(-500,-500,-500);
150 Point up(500,500,500);
153
156 {
162 }
163 std::set< Point > faces_set, pos_edges_set, neg_edges_set;
165
167 std::vector< Plane > face_planes;
169 bool planarity = true;
171 {
173 for ( auto v : faceVertices[ f ] )
174 X.push_back( vertices[ v ] );
175 face_planes[ f ] =
Plane( X[ 0 ], X[ 1 ], X[ 2 ] );
176 for ( int v = 3; v < X.size(); v++ )
177 if ( ! face_planes[ f ]( X[ v ] ) )
178 {
179 trace.
error() <<
"Face " << f <<
" is not planar." << std::endl;
180 planarity = false; break;
181 }
182 }
184 if ( ! planarity ) return 1;
187 {
189 for ( auto v : faceVertices[ f ] )
190 X.push_back( vertices[ v ] );
192 faces_set.insert( F.cbegin(), F.cend() );
193 for ( int i = 0; i < X.size(); i++ )
194 {
196 if ( Y[ 1 ] < Y[ 0 ] ) std::swap( Y[ 0 ], Y[ 1 ] );
197 int idx1 = faceVertices[ f ][ i ];
198 int idx2 = faceVertices[ f ][ (i+1)%X.size() ];
199
200
201
203 bool pos = idx1 < idx2;
204 (pos ? pos_edges_set : neg_edges_set).
insert( A.cbegin(), A.cend() );
205 }
206 }
208 std::vector< Point > face_points, common_edge_points, arc_points, final_arc_points ;
209 std::vector< Point > pos_edge_points, neg_edge_points, both_edge_points;
210 std::vector< Point > vertex_points =
vertices;
211 std::sort( vertex_points.begin(), vertex_points.end() );
212 std::set_symmetric_difference( pos_edges_set.cbegin(), pos_edges_set.cend(),
213 neg_edges_set.cbegin(), neg_edges_set.cend(),
214 std::back_inserter( arc_points ) );
215 std::set_intersection( pos_edges_set.cbegin(), pos_edges_set.cend(),
216 neg_edges_set.cbegin(), neg_edges_set.cend(),
217 std::back_inserter( common_edge_points ) );
218 std::set_union( pos_edges_set.cbegin(), pos_edges_set.cend(),
219 neg_edges_set.cbegin(), neg_edges_set.cend(),
220 std::back_inserter( both_edge_points ) );
221 std::set_difference( faces_set.cbegin(), faces_set.cend(),
222 both_edge_points.cbegin(), both_edge_points.cend(),
223 std::back_inserter( face_points ) );
224 std::set_difference( pos_edges_set.cbegin(), pos_edges_set.cend(),
225 common_edge_points.cbegin(), common_edge_points.cend(),
226 std::back_inserter( pos_edge_points ) );
227 std::set_difference( neg_edges_set.cbegin(), neg_edges_set.cend(),
228 common_edge_points.cbegin(), common_edge_points.cend(),
229 std::back_inserter( neg_edge_points ) );
230 std::set_difference( common_edge_points.cbegin(), common_edge_points.cend(),
231 vertex_points.cbegin(), vertex_points.cend(),
232 std::back_inserter( final_arc_points ) );
233 auto total = vertex_points.size() + pos_edge_points.size()
234 + neg_edge_points.size()
235 + final_arc_points.size() + face_points.size();
236 trace.
info() <<
"#vertex points=" << vertex_points.size() << std::endl;
237 trace.
info() <<
"#pos edge points=" << pos_edge_points.size() << std::endl;
238 trace.
info() <<
"#neg edge points=" << neg_edge_points.size() << std::endl;
239 trace.
info() <<
"#arc points=" << final_arc_points.size() << std::endl;
240 trace.
info() <<
"#face points=" << face_points.size() << std::endl;
241 trace.
info() <<
"#total points=" << total << std::endl;
242
243
247 if ( view & 0x1 )
248 {
249 viewer.setLineColor( colors[ 0 ] );
250 viewer.setFillColor( colors[ 0 ] );
251 for ( auto p : vertices ) viewer << p;
252 }
253 if ( view & 0x2 )
254 {
255 viewer.setLineColor( colors[ 3 ] );
256 viewer.setFillColor( colors[ 3 ] );
257 for ( auto p : final_arc_points ) viewer << p;
258 }
259 if ( view & 0x4 )
260 {
261 viewer.setLineColor( colors[ 1 ] );
262 viewer.setFillColor( colors[ 1 ] );
263 for ( auto p : pos_edge_points ) viewer << p;
264 }
265 if ( view & 0x8 )
266 {
267 viewer.setLineColor( colors[ 2 ] );
268 viewer.setFillColor( colors[ 2 ] );
269 for ( auto p : neg_edge_points ) viewer << p;
270 }
271 if ( view & 0x10 )
272 {
273 viewer.setLineColor( colors[ 4 ] );
274 viewer.setFillColor( colors[ 4 ] );
275 for ( auto p : face_points ) viewer << p;
276 }
277 viewer << MViewer::updateDisplay;
278 return application.exec();
279
280}
Structure representing an RGB triple with alpha component.
static const Color Magenta
PointRange relativeEnvelope(const PointRange &Z, const PointRange &Y, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
void beginBlock(const std::string &keyword="")
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
std::vector< Point > PointRange
Point::Coordinate Integer
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
MedianPlane< false, true > Plane
static bool readOBJ(std::istream &input, SurfaceMesh &smesh)
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
const std::vector< Vertices > & allIncidentVertices() const
RealPoint & position(Vertex v)
void insert(VContainer1 &c1, LContainer2 &c2, unsigned int idx, double v)