Commit 901b830f authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Read of binary ply files independently of endianness

parent 82646324
......@@ -207,7 +207,7 @@ void Approximator_MidEdge<PFP>::approximate(Dart d)
Dart d2 = m.phi2(m.phi_1(d)) ;
Dart dd2 = m.phi2(m.phi_1(dd)) ;
VEC3 v2 = this->m_attrV[dd] ;
// VEC3 v2 = this->m_attrV[dd] ;
// temporary edge collapse
m.extractTrianglePair(d) ;
......@@ -297,9 +297,9 @@ void Approximator_CornerCutting<PFP>::approximate(Dart d)
// get some darts
Dart dd = m.phi2(d) ;
Dart d1 = m.phi2(m.phi1(d)) ;
// Dart d1 = m.phi2(m.phi1(d)) ;
Dart d2 = m.phi2(m.phi_1(d)) ;
Dart dd1 = m.phi2(m.phi1(dd)) ;
// Dart dd1 = m.phi2(m.phi1(dd)) ;
Dart dd2 = m.phi2(m.phi_1(dd)) ;
// get the contracted edge vertices positions
......
......@@ -26,6 +26,7 @@
#define __EXPORT_H__
#include "Topology/generic/attributeHandler.h"
#include <stdint.h>
namespace CGoGN
{
......@@ -87,7 +88,7 @@ bool exportTrian(typename PFP::MAP& map, const typename PFP::TVEC3& position, ch
* @param filename filename of ply file
* @param position the position container
* @return true
*/
*
template <typename PFP>
bool exportPlySLFgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
......@@ -102,7 +103,7 @@ bool exportPlySLFgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& posi
* @param filename filename of ply file
* @param position the position container
* @return true
*/
*
template <typename PFP>
bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
......
......@@ -308,7 +308,7 @@ bool exportPLYnew(typename PFP::MAP& map, const std::vector<typename PFP::TVEC3*
// binary faces
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
unsigned char nbe = facesSize[i] ;
uint8_t nbe = facesSize[i] ;
out.write((char*)(&nbe), sizeof(unsigned char)) ;
out.write((char*)(&(facesIdx[i][0])), facesSize[i] * sizeof(facesIdx[i][0])) ;
}
......@@ -527,7 +527,7 @@ bool exportPlyPTMgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& posi
out.close() ;
return true ;
}
/*
template <typename PFP>
bool exportPlySLFgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good)
{
......@@ -803,7 +803,7 @@ bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& p
out.close() ;
return true ;
}
*/
template <typename PFP>
bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename PFP::TVEC3& position, const typename PFP::TVEC3 frame[3], const typename PFP::TVEC3 colorPTM[6], const FunctorSelect& good)
......
......@@ -52,7 +52,7 @@ namespace Import
namespace ImportSurfacique
{
enum ImportType { UNKNOWNSURFACE, TRIAN, TRIANBGZ, MESHBIN, PLY, PLYPTM, PLYSLFgeneric, PLYSLFgenericBin, OFF, OBJ, VRML, AHEM };
enum ImportType { UNKNOWNSURFACE, TRIAN, TRIANBGZ, MESHBIN, PLY, /*PLYPTM, PLYSLFgeneric, PLYSLFgenericBin, */OFF, OBJ, VRML, AHEM };
}
namespace ImportVolumique
......@@ -115,10 +115,10 @@ public:
bool importPly(const std::string& filename, std::vector<std::string>& attrNames);
bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);
/* bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);
bool importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames);
bool importPlySLFgenericBin(const std::string& filename, std::vector<std::string>& attrNames);
*/
#ifdef WITH_ASSIMP
bool importASSIMP(const std::string& filename, std::vector<std::string>& attrNames);
#endif
......
......@@ -55,7 +55,7 @@ ImportSurfacique::ImportType MeshTablesSurface<PFP>::getFileType(const std::stri
if ((filename.rfind(".meshbin")!=std::string::npos) || (filename.rfind(".MESHBIN")!=std::string::npos))
return ImportSurfacique::MESHBIN;
if ((filename.rfind(".plyptm")!=std::string::npos) || (filename.rfind(".PLYGEN")!=std::string::npos))
/* if ((filename.rfind(".plyptm")!=std::string::npos) || (filename.rfind(".PLYGEN")!=std::string::npos))
return ImportSurfacique::PLYPTM;
if ((filename.rfind(".plyPTMextBin")!=std::string::npos) || (filename.rfind(".plySHrealBin")!=std::string::npos))
......@@ -63,7 +63,7 @@ ImportSurfacique::ImportType MeshTablesSurface<PFP>::getFileType(const std::stri
if ((filename.rfind(".plyPTMext")!=std::string::npos) || (filename.rfind(".plySHreal")!=std::string::npos))
return ImportSurfacique::PLYSLFgeneric;
*/
if ((filename.rfind(".ply")!=std::string::npos) || (filename.rfind(".PLY")!=std::string::npos))
return ImportSurfacique::PLY;
......@@ -108,7 +108,7 @@ bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector
CGoGNout << "TYPE: PLY" << CGoGNendl;
return importPly(filename, attrNames);
break;
case ImportSurfacique::PLYPTM:
/* case ImportSurfacique::PLYPTM:
CGoGNout << "TYPE: PLYPTM" << CGoGNendl;
return importPlyPTM(filename, attrNames);
break;
......@@ -120,7 +120,7 @@ bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector
CGoGNout << "TYPE: PLYSLFgenericBin" << CGoGNendl;
return importPlySLFgenericBin(filename, attrNames);
break;
*/
case ImportSurfacique::OBJ:
CGoGNout << "TYPE: OBJ" << CGoGNendl;
return importObj(filename, attrNames);
......@@ -652,9 +652,9 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
* @param attrNames reference that will be filled with the attribute names
* the number of attrNames returned depends on the degree of the polynomials / level of the SH :
* - 1 attrName for geometric position (VEC3) : name = "position" ;
* - 3 attrNames for local frame (3xVEC3) : names are "Frame_T" (Tangent), "Frame_B" (Binormal) and "Frame_N" (Normal) ;
* - 3 attrNames for local frame (3xVEC3) : names are "frameT" (Tangent), "frameB" (Binormal) and "frameN" (Normal) ;
* - N attrNames for the function coefficients (NxVEC3) : N RGB coefficients being successively the constants, the linears (v then u), the quadratics, etc. : : a0 + a1*v + a2*u + a3*u*v + a4*v^2 + a5*u^2.
* Their names are : "SLFcoefs_<i>" (where <i> is a number from 0 to N-1).
* Their names are : "SLFcoefs<i>" (where <i> is a number from 0 to N-1).
* N = 1 for constant polynomial,
* N = 3 for linear polynomial,
* N = 6 for quadratic polynomial,
......@@ -665,7 +665,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
* ...
* - K remaining attrNames named "remainderNo<k>" where k is an integer from 0 to K-1.
* @return bool : success.
*/
*
template <typename PFP>
bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames)
{
......@@ -708,13 +708,13 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z"))
position = true ;
else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz"))
else if (tag == std::string("FrameT_0") || tag == std::string("FrameT_1") || tag == std::string("FrameT_2"))
tangent = true ;
else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz"))
else if (tag == std::string("FrameB_0") || tag == std::string("FrameB_1") || tag == std::string("FrameB_2"))
binormal = true ;
else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz"))
else if (tag == std::string("FrameN_0") || tag == std::string("FrameN_1") || tag == std::string("FrameN_2"))
normal = true ;
if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_"))
if ((tag.substr(3,5) == std::string("coefs") && tag.substr(8,1) == std::string("_")) || (tag.substr(2,5) == std::string("coefs") && tag.substr(7,1) == std::string("_")))
++nbCoefs ;
} while (tag != std::string("face")) ;
unsigned int nbRemainders = nbProps ; // # remaining properties
......@@ -735,9 +735,9 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
attrNames.push_back(positions.name()) ;
AttributeHandler<typename PFP::VEC3> *frame = new AttributeHandler<typename PFP::VEC3>[3] ;
frame[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_T") ; // Tangent
frame[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_B") ; // Bitangent
frame[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_N") ; // Normal
frame[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frameT") ; // Tangent
frame[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frameB") ; // Bitangent
frame[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frameN") ; // Normal
attrNames.push_back(frame[0].name()) ;
attrNames.push_back(frame[1].name()) ;
attrNames.push_back(frame[2].name()) ;
......@@ -746,7 +746,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
for (unsigned int i = 0 ; i < nbCoefs ; ++i)
{
std::stringstream name ;
name << "SLFcoefs_" << i ;
name << "SLFcoefs" << i ;
SLFcoefs[i] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, name.str()) ;
attrNames.push_back(SLFcoefs[i].name()) ;
}
......@@ -854,13 +854,13 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z"))
position = true ;
else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz"))
else if (tag == std::string("FrameT_0") || tag == std::string("FrameT_1") || tag == std::string("FrameT_2"))
tangent = true ;
else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz"))
else if (tag == std::string("FrameB_0") || tag == std::string("FrameB_1") || tag == std::string("FrameB_2"))
binormal = true ;
else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz"))
else if (tag == std::string("FrameN_0") || tag == std::string("FrameN_1") || tag == std::string("FrameN_2"))
normal = true ;
if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_"))
if ((tag.substr(3,5) == std::string("coefs") && tag.substr(8,1) == std::string("_")) || (tag.substr(2,5) == std::string("coefs") && tag.substr(7,1) == std::string("_")))
++nbCoefs ;
} while (tag != std::string("face")) ;
unsigned int nbRemainders = nbProps ; // # remaining properties
......@@ -888,9 +888,9 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
attrNames.push_back(positions.name()) ;
AttributeHandler<typename PFP::VEC3> *frame = new AttributeHandler<typename PFP::VEC3>[3] ;
frame[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_T") ; // Tangent
frame[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_B") ; // Bitangent
frame[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_N") ; // Normal
frame[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frameT") ; // Tangent
frame[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frameB") ; // Bitangent
frame[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frameN") ; // Normal
attrNames.push_back(frame[0].name()) ;
attrNames.push_back(frame[1].name()) ;
attrNames.push_back(frame[2].name()) ;
......@@ -899,7 +899,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
for (unsigned int i = 0 ; i < nbCoefs ; ++i)
{
std::stringstream name ;
name << "SLFcoefs_" << i ;
name << "SLFcoefs" << i ;
SLFcoefs[i] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, name.str()) ;
attrNames.push_back(SLFcoefs[i].name()) ;
}
......@@ -974,7 +974,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
* - 3 attrNames for local frame (3xVEC3) : Tangent, Bitangent and Normal vector
* - 6 attrNames for the function coefficients (6xVEC3) : 6 RGB coefficients being successively the quadratic members, the linears and the constants (u then v) : a*u^2 + b*v^2 + c*uv + d*u + e*v +f.
* @return bool : success.
*/
*
template <typename PFP>
bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames)
{
......@@ -1100,7 +1100,7 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect
fp.close();
return true;
}
*/
template <typename PFP>
......
......@@ -31,6 +31,7 @@
#include <QWidget>
#include <QtGui>
#include "Utils/Qt/qtgl.h"
#include <set>
#include <string>
#include "Geometry/vector_gen.h"
......
......@@ -102,7 +102,7 @@ double get_item_value(char *, int);
/* get binary or ascii item and store it according to ptr and type */
void get_ascii_item(char *, int, int *, unsigned int *, double *);
void get_binary_item(FILE *, int, int *, unsigned int *, double *);
void get_binary_item(FILE *, int, int *, unsigned int *, double *, int);
/* get a bunch of elements from a file */
void ascii_get_element(PlyFile *, char *);
......@@ -1603,7 +1603,8 @@ void binary_get_element(PlyFile *plyfile, char *elem_ptr)
/* get and store the number of items in the list */
get_binary_item (fp, prop->count_external,
&int_val, &uint_val, &double_val);
&int_val, &uint_val, &double_val,
plyfile->file_type);
if (store_it) {
item = elem_data + prop->count_offset;
store_item(item, prop->count_internal, int_val, uint_val, double_val);
......@@ -1627,7 +1628,8 @@ void binary_get_element(PlyFile *plyfile, char *elem_ptr)
/* read items and store them into the array */
for (k = 0; k < list_count; k++) {
get_binary_item (fp, prop->external_type,
&int_val, &uint_val, &double_val);
&int_val, &uint_val, &double_val,
plyfile->file_type);
if (store_it) {
store_item (item, prop->internal_type,
int_val, uint_val, double_val);
......@@ -1652,7 +1654,8 @@ void binary_get_element(PlyFile *plyfile, char *elem_ptr)
}
else { /* scalar */
get_binary_item (fp, prop->external_type,
&int_val, &uint_val, &double_val);
&int_val, &uint_val, &double_val,
plyfile->file_type);
if (store_it) {
item = elem_data + prop->offset;
store_item (item, prop->internal_type, int_val, uint_val, double_val);
......@@ -2059,7 +2062,8 @@ void get_binary_item(
int type,
int *int_val,
unsigned int *uint_val,
double *double_val
double *double_val,
int file_type
)
{
char c[8];
......@@ -2067,52 +2071,103 @@ void get_binary_item(
ptr = (void *) c;
int tmp = 1 ;
int my_endianness = (tmp >> 8) ? PLY_BINARY_BE : PLY_BINARY_LE ;
switch (type) {
case PLY_Int8:
fread (ptr, 1, 1, fp);
*int_val = *((char *) ptr);
*uint_val = *int_val;
*double_val = *int_val;
break;
fread (ptr, 1, 1, fp);
*int_val = *((char *) ptr);
*uint_val = *int_val;
*double_val = *int_val;
break;
case PLY_Uint8:
fread (ptr, 1, 1, fp);
*uint_val = *((unsigned char *) ptr);
*int_val = *uint_val;
*double_val = *uint_val;
break;
fread (ptr, 1, 1, fp);
*uint_val = *((unsigned char *) ptr);
*int_val = *uint_val;
*double_val = *uint_val;
break;
case PLY_Int16:
fread (ptr, 2, 1, fp);
*int_val = *((short int *) ptr);
*uint_val = *int_val;
*double_val = *int_val;
break;
if (my_endianness != file_type)
{
fread (ptr+1, 1, 1, fp);
fread (ptr+0, 1, 1, fp);
}
else
fread (ptr, 2, 1, fp);
*int_val = *((short*) ptr) ;
*uint_val = *int_val;
*double_val = *int_val;
break;
case PLY_Uint16:
fread (ptr, 2, 1, fp);
*uint_val = *((unsigned short int *) ptr);
*int_val = *uint_val;
*double_val = *uint_val;
break;
if (my_endianness != file_type)
{
fread (ptr+1, 1, 1, fp);
fread (ptr+0, 1, 1, fp);
}
else
fread (ptr, 2, 1, fp);
*uint_val = *((unsigned short*) ptr) ;
*int_val = *uint_val;
*double_val = *uint_val;
break;
case PLY_Int32:
fread (ptr, 4, 1, fp);
*int_val = *((int *) ptr);
*uint_val = *int_val;
*double_val = *int_val;
if (my_endianness != file_type)
{
fread (ptr+3, 1, 1, fp);
fread (ptr+2, 1, 1, fp);
fread (ptr+1, 1, 1, fp);
fread (ptr+0, 1, 1, fp);
}
else
fread (ptr, 4, 1, fp);
*int_val = *((int*) ptr) ;
*uint_val = *int_val;
*double_val = *int_val;
break;
case PLY_Uint32:
fread (ptr, 4, 1, fp);
*uint_val = *((unsigned int *) ptr);
*int_val = *uint_val;
*double_val = *uint_val;
if (my_endianness != file_type)
{
fread (ptr+3, 1, 1, fp);
fread (ptr+2, 1, 1, fp);
fread (ptr+1, 1, 1, fp);
fread (ptr+0, 1, 1, fp);
}
else
fread (ptr, 4, 1, fp);
*uint_val = *((unsigned int*) ptr) ;
*int_val = *uint_val;
*double_val = *uint_val;
break;
case PLY_Float32:
fread (ptr, 4, 1, fp);
*double_val = *((float *) ptr);
*int_val = *double_val;
*uint_val = *double_val;
if (my_endianness != file_type)
{
fread (ptr+3, 1, 1, fp);
fread (ptr+2, 1, 1, fp);
fread (ptr+1, 1, 1, fp);
fread (ptr+0, 1, 1, fp);
}
else
fread (ptr, 4, 1, fp);
*double_val = *((float*) ptr) ;
*int_val = *double_val;
*uint_val = *double_val;
break;
case PLY_Float64:
fread (ptr, 8, 1, fp);
*double_val = *((double *) ptr);
if (my_endianness != file_type)
{
fread (ptr+7, 1, 1, fp);
fread (ptr+6, 1, 1, fp);
fread (ptr+5, 1, 1, fp);
fread (ptr+4, 1, 1, fp);
fread (ptr+3, 1, 1, fp);
fread (ptr+2, 1, 1, fp);
fread (ptr+1, 1, 1, fp);
fread (ptr+0, 1, 1, fp);
}
else
fread (ptr, 8, 1, fp);
*double_val = *((double*) ptr) ;
*int_val = *double_val;
*uint_val = *double_val;
break;
......@@ -2120,6 +2175,11 @@ void get_binary_item(
fprintf (stderr, "get_binary_item: bad type = %d\n", type);
exit (-1);
}
/*printf("%d\n",*int_val) ;
printf("%u\n",*uint_val) ;
printf("%f\n",*double_val) ;
*/
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment