mirror of https://github.com/CGAL/cgal
Fix OFF_reading
This commit is contained in:
parent
b16249b99a
commit
277b8cc74b
|
|
@ -214,7 +214,7 @@ namespace CGAL {
|
||||||
for (std::size_t j=0; j<no; j++)
|
for (std::size_t j=0; j<no; j++)
|
||||||
{
|
{
|
||||||
std::size_t index;
|
std::size_t index;
|
||||||
scanner.scan_facet_vertex_index(index, i);
|
scanner.scan_facet_vertex_index(index, j+1, i);
|
||||||
B.add_vertex_to_facet(index);
|
B.add_vertex_to_facet(index);
|
||||||
}
|
}
|
||||||
B.end_facet();
|
B.end_facet();
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ std::istream& read_soup(
|
||||||
|
|
||||||
for(std::size_t j = 0; j < no; ++j) {
|
for(std::size_t j = 0; j < no; ++j) {
|
||||||
std::size_t id;
|
std::size_t id;
|
||||||
scanner.scan_facet_vertex_index(id, i);
|
scanner.scan_facet_vertex_index(id, j+1, i);
|
||||||
if(id < scanner.size_of_vertices())
|
if(id < scanner.size_of_vertices())
|
||||||
{
|
{
|
||||||
polygons[i][j] = id;
|
polygons[i][j] = id;
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ void Polyhedron_scan_OFF<HDS>:: operator()(HDS& target)
|
||||||
Point p;
|
Point p;
|
||||||
file_scan_vertex( scanner, p);
|
file_scan_vertex( scanner, p);
|
||||||
B.add_vertex( p);
|
B.add_vertex( p);
|
||||||
if(scanner.has_colors())
|
if(scanner.has_vcolors())
|
||||||
{
|
{
|
||||||
Color c;
|
Color c;
|
||||||
file_scan_color(scanner, c);
|
file_scan_color(scanner, c);
|
||||||
|
|
@ -125,11 +125,9 @@ void Polyhedron_scan_OFF<HDS>:: operator()(HDS& target)
|
||||||
for(std::size_t j=0; j<no; ++j)
|
for(std::size_t j=0; j<no; ++j)
|
||||||
{
|
{
|
||||||
std::size_t index;
|
std::size_t index;
|
||||||
scanner.scan_facet_vertex_index( index, i);
|
scanner.scan_facet_vertex_index( index, j+1, i); //current_entry = j + 1 for the size entry
|
||||||
B.add_vertex_to_facet( index);
|
B.add_vertex_to_facet( index);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TO DO : Insert read color
|
|
||||||
B.end_facet();
|
B.end_facet();
|
||||||
scanner.skip_to_next_facet( i);
|
scanner.skip_to_next_facet( i);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ int main( int argc, char **argv)
|
||||||
writer.write_facet_begin( no);
|
writer.write_facet_begin( no);
|
||||||
for ( std::size_t j = 0; j < no; j++) {
|
for ( std::size_t j = 0; j < no; j++) {
|
||||||
std::size_t index;
|
std::size_t index;
|
||||||
scanner.scan_facet_vertex_index( index, i);
|
scanner.scan_facet_vertex_index( index, j+1, i);
|
||||||
writer.write_facet_vertex_index( vertices[index].index);
|
writer.write_facet_vertex_index( vertices[index].index);
|
||||||
}
|
}
|
||||||
scanner.skip_to_next_facet( i);
|
scanner.skip_to_next_facet( i);
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ bool read_OFF(std::istream& is,
|
||||||
*vn_out++ = Normal(FT(nx), FT(ny), FT(nz), FT(nw));
|
*vn_out++ = Normal(FT(nx), FT(ny), FT(nz), FT(nw));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scanner.has_colors())
|
if(scanner.has_vcolors())
|
||||||
{
|
{
|
||||||
unsigned char r=0, g=0, b=0;
|
unsigned char r=0, g=0, b=0;
|
||||||
scanner.scan_color(r, g, b);
|
scanner.scan_color(r, g, b);
|
||||||
|
|
@ -108,15 +108,11 @@ bool read_OFF(std::istream& is,
|
||||||
CGAL_assertion(nw != 0);
|
CGAL_assertion(nw != 0);
|
||||||
*vt_out++ = Texture(nx, ny, nw);
|
*vt_out++ = Texture(nx, ny, nw);
|
||||||
}
|
}
|
||||||
if(!scanner.eol())
|
|
||||||
scanner.skip_to_next_vertex(i);
|
|
||||||
scanner.set_eol(false);
|
|
||||||
|
|
||||||
if(!is.good())
|
if(!is.good())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_fcolors = false;
|
|
||||||
for(std::size_t i=0; i<scanner.size_of_facets(); ++i)
|
for(std::size_t i=0; i<scanner.size_of_facets(); ++i)
|
||||||
{
|
{
|
||||||
std::size_t no(-1);
|
std::size_t no(-1);
|
||||||
|
|
@ -129,29 +125,13 @@ bool read_OFF(std::istream& is,
|
||||||
for(std::size_t j=0; j<no; ++j)
|
for(std::size_t j=0; j<no; ++j)
|
||||||
{
|
{
|
||||||
std::size_t id;
|
std::size_t id;
|
||||||
scanner.scan_facet_vertex_index(id, i);
|
scanner.scan_facet_vertex_index(id,j+1, i);
|
||||||
if(id < scanner.size_of_vertices())
|
if(id < scanner.size_of_vertices())
|
||||||
polygons[i][j] = id;
|
polygons[i][j] = id;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(scanner.has_fcolors())
|
||||||
if(i == 0)
|
|
||||||
{
|
|
||||||
std::string col;
|
|
||||||
std::getline(is, col);
|
|
||||||
std::istringstream iss(col);
|
|
||||||
char ci =' ';
|
|
||||||
|
|
||||||
if(iss >> ci)
|
|
||||||
{
|
|
||||||
has_fcolors = true;
|
|
||||||
std::istringstream iss2(col);
|
|
||||||
bool dum;
|
|
||||||
*fc_out++ = scanner.get_color_from_line(iss2, dum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(has_fcolors)
|
|
||||||
{
|
{
|
||||||
unsigned char r=0, g=0, b=0;
|
unsigned char r=0, g=0, b=0;
|
||||||
scanner.scan_color(r,g,b);
|
scanner.scan_color(r,g,b);
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ private:
|
||||||
// Publicly accessible but not that well supported file informations.
|
// Publicly accessible but not that well supported file informations.
|
||||||
bool m_textures; // STOFF detected.
|
bool m_textures; // STOFF detected.
|
||||||
bool m_colors; // COFF detected.
|
bool m_colors; // COFF detected.
|
||||||
|
protected:
|
||||||
|
bool m_has_vcolors;
|
||||||
|
bool m_has_fcolors;
|
||||||
|
private:
|
||||||
bool m_normals; // NOFF format stores also normals at vertices.
|
bool m_normals; // NOFF format stores also normals at vertices.
|
||||||
|
|
||||||
// More privately used file informations to scan the file.
|
// More privately used file informations to scan the file.
|
||||||
|
|
@ -81,6 +85,8 @@ public:
|
||||||
std::size_t index_offset() const { return m_offset; }
|
std::size_t index_offset() const { return m_offset; }
|
||||||
bool has_textures() const { return m_textures; } // STOFF detected.
|
bool has_textures() const { return m_textures; } // STOFF detected.
|
||||||
bool has_colors() const { return m_colors; } // COFF detected.
|
bool has_colors() const { return m_colors; } // COFF detected.
|
||||||
|
bool has_vcolors() const { return m_has_vcolors; } // COFF detected.
|
||||||
|
bool has_fcolors() const { return m_has_fcolors; } // COFF detected.
|
||||||
bool has_normals() const { return m_normals;} // NOFF format.
|
bool has_normals() const { return m_normals;} // NOFF format.
|
||||||
bool is_homogeneous() const { return m_tag4; } // 4OFF detected.
|
bool is_homogeneous() const { return m_tag4; } // 4OFF detected.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ File_header_OFF::File_header_OFF( bool verbose)
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
@ -62,6 +64,8 @@ File_header_OFF::File_header_OFF(
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
@ -98,6 +102,8 @@ File_header_OFF::File_header_OFF( std::size_t v, std::size_t h, std::size_t f,
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
@ -117,6 +123,8 @@ File_header_OFF::File_header_OFF(
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
@ -135,6 +143,8 @@ File_header_OFF::File_header_OFF(
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
@ -153,6 +163,8 @@ File_header_OFF::File_header_OFF(
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
@ -174,6 +186,8 @@ File_header_OFF::File_header_OFF(
|
||||||
m_offset(0),
|
m_offset(0),
|
||||||
m_textures(false),
|
m_textures(false),
|
||||||
m_colors(false),
|
m_colors(false),
|
||||||
|
m_has_vcolors(false),
|
||||||
|
m_has_fcolors(false),
|
||||||
m_normals(false),
|
m_normals(false),
|
||||||
m_tag4(false),
|
m_tag4(false),
|
||||||
m_tagDim(false),
|
m_tagDim(false),
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -167,7 +167,7 @@ private:
|
||||||
// A huge value helps to detect a potential
|
// A huge value helps to detect a potential
|
||||||
// error in the function scan_facet_vertex_index
|
// error in the function scan_facet_vertex_index
|
||||||
for (std::size_t i = 0; i < no; ++i) {
|
for (std::size_t i = 0; i < no; ++i) {
|
||||||
m_scan->scan_facet_vertex_index( index, m_cnt);
|
m_scan->scan_facet_vertex_index( index, i+1, m_cnt);
|
||||||
m_indices.push_back( index);
|
m_indices.push_back( index);
|
||||||
}
|
}
|
||||||
m_scan->skip_to_next_facet( m_cnt);
|
m_scan->skip_to_next_facet( m_cnt);
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ generic_copy_OFF(File_scanner_OFF& scanner,
|
||||||
for(std::size_t j=0; j<no; ++j)
|
for(std::size_t j=0; j<no; ++j)
|
||||||
{
|
{
|
||||||
std::size_t index;
|
std::size_t index;
|
||||||
scanner.scan_facet_vertex_index(index, i);
|
scanner.scan_facet_vertex_index(index, j+1, i);
|
||||||
writer.write_facet_vertex_index(index);
|
writer.write_facet_vertex_index(index);
|
||||||
}
|
}
|
||||||
writer.write_facet_end();
|
writer.write_facet_end();
|
||||||
|
|
|
||||||
|
|
@ -2342,7 +2342,7 @@ off_file_input( std::istream& is, bool verbose)
|
||||||
|
|
||||||
for ( std::size_t j = 0; j < no; ++j) {
|
for ( std::size_t j = 0; j < no; ++j) {
|
||||||
std::size_t index;
|
std::size_t index;
|
||||||
scanner.scan_facet_vertex_index( index, i);
|
scanner.scan_facet_vertex_index( index, j+1, i);
|
||||||
fh->set_vertex(j, vvh[index]);
|
fh->set_vertex(j, vvh[index]);
|
||||||
vvh[index]->set_face(fh);
|
vvh[index]->set_face(fh);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue