mirror of https://github.com/CGAL/cgal
remove the STL reading part outside of the builder
This commit is contained in:
parent
fcd2e56742
commit
00a57be25a
|
|
@ -66,18 +66,7 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene_polyhedron_item* item = new Scene_polyhedron_item(P);
|
Scene_polyhedron_item* item = new Scene_polyhedron_item(P);
|
||||||
if(builder.name.size() == 0){
|
item->setName(fileinfo.baseName());
|
||||||
item->setName(fileinfo.baseName());
|
|
||||||
} else {
|
|
||||||
item->setName(builder.name.c_str());
|
|
||||||
}
|
|
||||||
QColor color(builder.color.c_str());
|
|
||||||
if(color.isValid())
|
|
||||||
{
|
|
||||||
item->setColor(color);
|
|
||||||
item->changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <CGAL/Modifier_base.h>
|
#include <CGAL/Modifier_base.h>
|
||||||
#include <CGAL/Polyhedron_incremental_builder_3.h>
|
#include <CGAL/Polyhedron_incremental_builder_3.h>
|
||||||
#include <CGAL/array.h>
|
#include <CGAL/IO/STL_reader.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
@ -30,96 +30,33 @@ namespace CGAL{
|
||||||
template <class HDS>
|
template <class HDS>
|
||||||
class Polyhedron_builder_from_STL : public CGAL::Modifier_base<HDS> {
|
class Polyhedron_builder_from_STL : public CGAL::Modifier_base<HDS> {
|
||||||
typedef typename HDS::Vertex::Point Point_3;
|
typedef typename HDS::Vertex::Point Point_3;
|
||||||
typedef std::vector<Point_3> Points_3;
|
typedef std::vector<cpp11::array<double, 3> > Points_3;
|
||||||
typedef cpp11::array<int,3> Facet;
|
typedef cpp11::array<int,3> Facet;
|
||||||
typedef std::vector<Facet> Surface;
|
typedef std::vector<Facet> Surface;
|
||||||
|
|
||||||
std::istream& is;
|
std::istream& is;
|
||||||
int counter;
|
|
||||||
Points_3 meshPoints;
|
Points_3 meshPoints;
|
||||||
Surface mesh;
|
Surface mesh;
|
||||||
|
|
||||||
bool
|
|
||||||
read(std::istream& input, Points_3& points, Surface& surface, int /*offset*/ = 0)
|
|
||||||
{
|
|
||||||
std::string s, solid("solid"), facet("facet"), outer("outer"), loop("loop"), vertex("vertex"), endloop("endloop"), endsolid("endsolid");
|
|
||||||
|
|
||||||
std::map<Point_3, int> vertex_index;
|
|
||||||
int index = 0;
|
|
||||||
cpp11::array<int,3> ijk;
|
|
||||||
Point_3 p;
|
|
||||||
|
|
||||||
input >> s;
|
|
||||||
if(s == solid){
|
|
||||||
std::getline(input, s);
|
|
||||||
} else {
|
|
||||||
std::cerr << "We expect keyword 'solid'" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(input >> s){
|
|
||||||
if(s == endsolid){
|
|
||||||
//std::cerr << "found endsolid" << std::endl;
|
|
||||||
} else if(s == facet){
|
|
||||||
//std::cerr << "found facet" << std::endl;
|
|
||||||
std::getline(input, s); // ignore the normal
|
|
||||||
input >> s;
|
|
||||||
if(s != outer){
|
|
||||||
std::cerr << "Expect 'outer' and got " << s << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
input >> s;
|
|
||||||
if(s != loop){
|
|
||||||
std::cerr << "Expect 'loop' and got " << s << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int count = 0;
|
|
||||||
do {
|
|
||||||
input >> s;
|
|
||||||
if(s == vertex){
|
|
||||||
// std::cerr << "found vertex" << std::endl;
|
|
||||||
if(count < 3){
|
|
||||||
input >> p;
|
|
||||||
typename std::map<Point_3, int>::iterator iti=
|
|
||||||
vertex_index.insert(std::make_pair(p,-1)).first;
|
|
||||||
if(iti->second==-1){
|
|
||||||
ijk[count] = index;
|
|
||||||
iti->second = index++;
|
|
||||||
points.push_back(p);
|
|
||||||
} else {
|
|
||||||
ijk[count] = iti->second;
|
|
||||||
}
|
|
||||||
++count;
|
|
||||||
} else {
|
|
||||||
std::cerr << "We can only read triangulated surfaces" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}while(s != endloop);
|
|
||||||
|
|
||||||
surface.push_back(ijk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Polyhedron_builder_from_STL(std::istream& is_)
|
Polyhedron_builder_from_STL(std::istream& is_)
|
||||||
: is(is_), counter(0)
|
: is(is_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void operator()( HDS& hds) {
|
void operator()( HDS& hds) {
|
||||||
if(!read(is, meshPoints, mesh)) return;
|
if(!read_STL(is, meshPoints, mesh)) return;
|
||||||
|
|
||||||
CGAL::Polyhedron_incremental_builder_3<HDS> B(hds);
|
CGAL::Polyhedron_incremental_builder_3<HDS> B(hds);
|
||||||
B.begin_surface( meshPoints.size(), mesh.size());
|
B.begin_surface( meshPoints.size(), mesh.size());
|
||||||
typedef typename Points_3::size_type size_type;
|
typedef typename Points_3::size_type size_type;
|
||||||
|
|
||||||
for(size_type i=0; i < meshPoints.size(); i++){
|
for(size_type i=0; i < meshPoints.size(); i++){
|
||||||
B.add_vertex( meshPoints[i]);
|
B.add_vertex(
|
||||||
|
Point_3(meshPoints[i][0], meshPoints[i][1], meshPoints[i][2])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_type i=0; i < mesh.size(); i++){
|
for(size_type i=0; i < mesh.size(); i++){
|
||||||
B.begin_facet();
|
B.begin_facet();
|
||||||
B.add_vertex_to_facet( mesh[i][0]);
|
B.add_vertex_to_facet( mesh[i][0]);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
// Copyright (c) 2015 GeometryFactory
|
||||||
|
//
|
||||||
|
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 3 of the License,
|
||||||
|
// or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Licensees holding a valid commercial license may use this file in
|
||||||
|
// accordance with the commercial license agreement provided with the software.
|
||||||
|
//
|
||||||
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// $URL$
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Author(s) : Andreas Fabri
|
||||||
|
|
||||||
|
#ifndef CGAL_IO_STL_READER_H
|
||||||
|
#define CGAL_IO_STL_READER_H
|
||||||
|
|
||||||
|
#include <CGAL/array.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace CGAL{
|
||||||
|
|
||||||
|
bool
|
||||||
|
read_STL( std::istream& input,
|
||||||
|
std::vector< cpp11::array<double,3> >& points,
|
||||||
|
std::vector< cpp11::array<int,3> >& facets,
|
||||||
|
bool verbose = false)
|
||||||
|
{
|
||||||
|
std::string s,
|
||||||
|
solid("solid"),
|
||||||
|
facet("facet"),
|
||||||
|
outer("outer"),
|
||||||
|
loop("loop"),
|
||||||
|
vertex("vertex"),
|
||||||
|
endloop("endloop"),
|
||||||
|
endsolid("endsolid");
|
||||||
|
|
||||||
|
std::map<cpp11::array<double,3>, int> vertex_index;
|
||||||
|
int index = 0;
|
||||||
|
cpp11::array<int,3> ijk;
|
||||||
|
cpp11::array<double,3> p;
|
||||||
|
|
||||||
|
input >> s;
|
||||||
|
if(s == solid){
|
||||||
|
std::getline(input, s);
|
||||||
|
} else {
|
||||||
|
if (verbose)
|
||||||
|
std::cerr << "We expect keyword 'solid'" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(input >> s){
|
||||||
|
if(s == endsolid){
|
||||||
|
//std::cerr << "found endsolid" << std::endl;
|
||||||
|
} else if(s == facet){
|
||||||
|
//std::cerr << "found facet" << std::endl;
|
||||||
|
std::getline(input, s); // ignore the normal
|
||||||
|
input >> s;
|
||||||
|
if(s != outer){
|
||||||
|
if (verbose)
|
||||||
|
std::cerr << "Expect 'outer' and got " << s << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
input >> s;
|
||||||
|
if(s != loop){
|
||||||
|
if (verbose)
|
||||||
|
std::cerr << "Expect 'loop' and got " << s << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
do {
|
||||||
|
input >> s;
|
||||||
|
if(s == vertex){
|
||||||
|
// std::cerr << "found vertex" << std::endl;
|
||||||
|
if(count < 3){
|
||||||
|
input >> p[0] >> p[1] >> p[2];
|
||||||
|
typename std::map<cpp11::array<double,3>, int>::iterator iti=
|
||||||
|
vertex_index.insert(std::make_pair(p,-1)).first;
|
||||||
|
if(iti->second==-1){
|
||||||
|
ijk[count] = index;
|
||||||
|
iti->second = index++;
|
||||||
|
points.push_back(p);
|
||||||
|
} else {
|
||||||
|
ijk[count] = iti->second;
|
||||||
|
}
|
||||||
|
++count;
|
||||||
|
} else {
|
||||||
|
if (verbose)
|
||||||
|
std::cerr << "We can only read triangulated surfaces" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while(s != endloop);
|
||||||
|
|
||||||
|
facets.push_back(ijk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CGAL
|
||||||
|
|
||||||
|
#endif // CGAL_IO_STL_READER_H
|
||||||
Loading…
Reference in New Issue