Fix OFF_reading

This commit is contained in:
Maxime Gimeno 2020-11-25 13:20:26 +01:00
parent b16249b99a
commit 277b8cc74b
11 changed files with 220 additions and 677 deletions

View File

@ -214,7 +214,7 @@ namespace CGAL {
for (std::size_t j=0; j<no; j++)
{
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.end_facet();

View File

@ -46,7 +46,7 @@ std::istream& read_soup(
for(std::size_t j = 0; j < no; ++j) {
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())
{
polygons[i][j] = id;

View File

@ -86,7 +86,7 @@ void Polyhedron_scan_OFF<HDS>:: operator()(HDS& target)
Point p;
file_scan_vertex( scanner, p);
B.add_vertex( p);
if(scanner.has_colors())
if(scanner.has_vcolors())
{
Color 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)
{
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);
}
//TO DO : Insert read color
B.end_facet();
scanner.skip_to_next_facet( i);
}

View File

@ -185,7 +185,7 @@ int main( int argc, char **argv)
writer.write_facet_begin( no);
for ( std::size_t j = 0; j < no; j++) {
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);
}
scanner.skip_to_next_facet( i);

View File

@ -94,7 +94,7 @@ bool read_OFF(std::istream& is,
*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;
scanner.scan_color(r, g, b);
@ -108,15 +108,11 @@ bool read_OFF(std::istream& is,
CGAL_assertion(nw != 0);
*vt_out++ = Texture(nx, ny, nw);
}
if(!scanner.eol())
scanner.skip_to_next_vertex(i);
scanner.set_eol(false);
if(!is.good())
return false;
}
bool has_fcolors = false;
for(std::size_t i=0; i<scanner.size_of_facets(); ++i)
{
std::size_t no(-1);
@ -129,29 +125,13 @@ bool read_OFF(std::istream& is,
for(std::size_t j=0; j<no; ++j)
{
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())
polygons[i][j] = id;
else
return false;
}
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)
if(scanner.has_fcolors())
{
unsigned char r=0, g=0, b=0;
scanner.scan_color(r,g,b);

View File

@ -40,6 +40,10 @@ private:
// Publicly accessible but not that well supported file informations.
bool m_textures; // STOFF 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.
// More privately used file informations to scan the file.
@ -81,6 +85,8 @@ public:
std::size_t index_offset() const { return m_offset; }
bool has_textures() const { return m_textures; } // STOFF 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 is_homogeneous() const { return m_tag4; } // 4OFF detected.

View File

@ -45,6 +45,8 @@ File_header_OFF::File_header_OFF( bool verbose)
m_offset(0),
m_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(false),
m_tagDim(false),
@ -62,6 +64,8 @@ File_header_OFF::File_header_OFF(
m_offset(0),
m_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(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_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(false),
m_tagDim(false),
@ -117,6 +123,8 @@ File_header_OFF::File_header_OFF(
m_offset(0),
m_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(false),
m_tagDim(false),
@ -135,6 +143,8 @@ File_header_OFF::File_header_OFF(
m_offset(0),
m_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(false),
m_tagDim(false),
@ -153,6 +163,8 @@ File_header_OFF::File_header_OFF(
m_offset(0),
m_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(false),
m_tagDim(false),
@ -174,6 +186,8 @@ File_header_OFF::File_header_OFF(
m_offset(0),
m_textures(false),
m_colors(false),
m_has_vcolors(false),
m_has_fcolors(false),
m_normals(false),
m_tag4(false),
m_tagDim(false),

File diff suppressed because it is too large Load Diff

View File

@ -167,7 +167,7 @@ private:
// A huge value helps to detect a potential
// error in the function scan_facet_vertex_index
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_scan->skip_to_next_facet( m_cnt);

View File

@ -77,7 +77,7 @@ generic_copy_OFF(File_scanner_OFF& scanner,
for(std::size_t j=0; j<no; ++j)
{
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_end();

View File

@ -2342,7 +2342,7 @@ off_file_input( std::istream& is, bool verbose)
for ( std::size_t j = 0; j < no; ++j) {
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]);
vvh[index]->set_face(fh);
}