48 #include <OpenFlipper/Utils/Memory/RAMInfo.hh> 50 #include <QMessageBox> 51 #include <QVBoxLayout> 54 #define TYPEAUTODETECT 0 57 #define TYPETRIANGLE 3 59 using namespace Utils;
74 savePrecisionLabel_(0),
76 saveDefaultButton_(0),
83 loadCheckManifold_(0),
84 loadDefaultButton_(0),
87 forceTriangleMesh_(false),
88 forcePolyMesh_(false),
89 readColorComp_(false),
100 userReadOptions_ |= OFFImporter::VERTEXCOLOR;
102 userReadOptions_ |= OFFImporter::FACECOLOR;
104 userReadOptions_ |= OFFImporter::COLORALPHA;
106 userReadOptions_ |= OFFImporter::VERTEXNORMAL;
108 userReadOptions_ |= OFFImporter::VERTEXTEXCOORDS;
111 userWriteOptions_ |= OFFImporter::BINARY;
113 userWriteOptions_ |= OFFImporter::VERTEXCOLOR;
115 userWriteOptions_ |= OFFImporter::FACECOLOR;
117 userWriteOptions_ |= OFFImporter::COLORALPHA;
119 userWriteOptions_ |= OFFImporter::VERTEXNORMAL;
121 userWriteOptions_ |= OFFImporter::VERTEXTEXCOORDS;
128 return QString( tr(
"Object File Format files ( *.off )") );
134 return QString( tr(
"Object File Format files ( *.off )") );
146 void FileOFFPlugin::trimString( std::string& _string) {
149 size_t start = _string.find_first_not_of(
" \t\r\n");
150 size_t end = _string.find_last_not_of(
" \t\r\n");
152 if(( std::string::npos == start ) || ( std::string::npos == end))
155 _string = _string.substr( start, end-start+1 );
166 std::getline(ifs,_string);
172 if ( _string.size() != 0 ) {
175 if ( _string[0] !=
'#') {
180 if ( !_skipEmptyLines )
185 std::cerr <<
"End of file reached while searching for input!" << std::endl;
202 if( OpenFlipper::Options::nogui() )
206 if(loadVertexColor_) {
207 if(loadVertexColor_->isChecked()) userReadOptions_ |= OFFImporter::VERTEXCOLOR;
208 else {
if(userReadOptions_ & OFFImporter::VERTEXCOLOR) userReadOptions_ -= OFFImporter::VERTEXCOLOR; }
211 if(loadFaceColor_->isChecked()) userReadOptions_ |= OFFImporter::FACECOLOR;
212 else {
if(userReadOptions_ & OFFImporter::FACECOLOR) userReadOptions_ -= OFFImporter::FACECOLOR; }
215 if(loadAlpha_->isChecked()) userReadOptions_ |= OFFImporter::COLORALPHA;
216 else {
if(userReadOptions_ & OFFImporter::COLORALPHA) userReadOptions_ -= OFFImporter::COLORALPHA; }
219 if(loadNormals_->isChecked()) userReadOptions_ |= OFFImporter::VERTEXNORMAL;
220 else {
if(userReadOptions_ & OFFImporter::VERTEXNORMAL) userReadOptions_ -= OFFImporter::VERTEXNORMAL; }
223 if(loadTexCoords_->isChecked()) userReadOptions_ |= OFFImporter::VERTEXTEXCOORDS;
224 else {
if(userReadOptions_ & OFFImporter::VERTEXTEXCOORDS) userReadOptions_ -= OFFImporter::VERTEXTEXCOORDS; }
229 if(saveBinary_->isChecked()) userWriteOptions_ |= OFFImporter::BINARY;
230 else {
if(userWriteOptions_ & OFFImporter::BINARY) userWriteOptions_ -= OFFImporter::BINARY; }
232 if(saveVertexColor_) {
233 if(saveVertexColor_->isChecked()) userWriteOptions_ |= OFFImporter::VERTEXCOLOR;
234 else {
if(userWriteOptions_ & OFFImporter::VERTEXCOLOR) userWriteOptions_ -= OFFImporter::VERTEXCOLOR; }
237 if(saveFaceColor_->isChecked()) userWriteOptions_ |= OFFImporter::FACECOLOR;
238 else {
if(userWriteOptions_ & OFFImporter::FACECOLOR) userWriteOptions_ -= OFFImporter::FACECOLOR; }
241 if(saveAlpha_->isChecked()) userWriteOptions_ |= OFFImporter::COLORALPHA;
242 else {
if(userWriteOptions_ & OFFImporter::COLORALPHA) userWriteOptions_ -= OFFImporter::COLORALPHA; }
245 if(saveNormals_->isChecked()) userWriteOptions_ |= OFFImporter::VERTEXNORMAL;
246 else {
if(userWriteOptions_ & OFFImporter::VERTEXNORMAL) userWriteOptions_ -= OFFImporter::VERTEXNORMAL; }
249 if(saveTexCoords_->isChecked()) userWriteOptions_ |= OFFImporter::VERTEXTEXCOORDS;
250 else {
if(userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS) userWriteOptions_ -= OFFImporter::VERTEXTEXCOORDS; }
269 const unsigned int LINE_LEN = 4096;
272 std::ifstream ifs(_filename.toUtf8(), std::ios_base::binary);
274 if ( (!ifs.is_open()) || (!ifs.good())) {
276 emit log(
LOGERR, tr(
"Error: Could not read file options of specified OFF-file! Aborting."));
281 char line[LINE_LEN], *p;
282 ifs.getline(line, LINE_LEN);
285 int remainingChars = ifs.gcount();
288 while(remainingChars > 0) {
290 if ( ( remainingChars > 1 ) && ( p[0] ==
'S' && p[1] ==
'T') ) {
291 _importer.
addOption(OFFImporter::VERTEXTEXCOORDS);
294 }
else if ( ( remainingChars > 0 ) && ( p[0] ==
'C') ) {
295 _importer.
addOption(OFFImporter::VERTEXCOLOR);
298 }
else if ( ( remainingChars > 0 ) && ( p[0] ==
'N') ) {
299 _importer.
addOption(OFFImporter::VERTEXNORMAL);
302 }
else if ( ( remainingChars > 0 ) && (p[0] ==
'3' ) ) {
305 }
else if ( ( remainingChars > 0 ) && (p[0] ==
'4' ) ) {
307 std::cerr <<
"Error: Extended coordinates are currently not supported!" << std::endl;
310 }
else if ( ( remainingChars > 0 ) && (p[0] ==
'n' ) ) {
312 std::cerr <<
"Error: n-dimensional coordinates are currently not supported!" << std::endl;
315 }
else if ( ( remainingChars >= 3 ) && (p[0] ==
'O' && p[1] ==
'F' && p[2] ==
'F') ) {
319 }
else if ( ( remainingChars >= 6 ) && ( strncmp(p,
"BINARY", 6) == 0 ) ) {
320 _importer.
addOption(OFFImporter::BINARY);
323 }
else if ( ( remainingChars > 0 ) && ( p[0] ==
'#' ) ) {
336 unsigned int nV, nF, dummy_uint;
337 unsigned int vertexCount = 0;
338 unsigned int tmp_count = 0;
341 std::istringstream sstr;
343 if(_importer.isBinary()) {
350 readValue(ifs, dummy_uint);
352 for (uint i=0; i<nV && !ifs.eof(); ++i) {
354 for(
int i = 0; i < 3; ++i) readValue(ifs, dummy_f);
357 for(
int i = 0; i < 3; ++i) readValue(ifs, dummy_f);
360 if ( _importer.hasVertexColors() ) {
361 for(
int i = 0; i < 3; ++i) readValue(ifs, dummy_f);
364 if ( _importer.hasTextureCoords() ) {
365 for(
int i = 0; i < 2; ++i) readValue(ifs, dummy_f);
368 for (uint i=0; i<nF; ++i) {
370 readValue(ifs, tmp_count);
375 if(tmp_count > vertexCount) vertexCount = tmp_count;
380 for(uint i = 0; i < tmp_count; ++i) readValue(ifs, dummy_uint);
383 readValue(ifs, tmp_count);
385 if(!_importer.hasFaceColors() && tmp_count > 0) {
386 _importer.
addOption(OFFImporter::FACECOLOR);
390 for (uint i = 0; i < tmp_count; ++i) {
391 readValue(ifs, dummy_f);
404 if ( str.compare(
"OFF") == 0 ) {
415 for(
unsigned int i = 0; i < nV; ++i) {
422 for(
unsigned int i = 0; i < nF; ++i) {
429 if(tmp_count > vertexCount) vertexCount = tmp_count;
432 for(uint i = 0; i < tmp_count; ++i) {
435 emit log(
LOGERR,
"The OFF File is Malformatted! Aborting...");
443 if(!_importer.hasFaceColors()) {
445 _importer.
addOption(OFFImporter::FACECOLOR);
453 _importer.maxFaceValence(vertexCount);
455 if(vertexCount == 3) {
456 _importer.
addOption(OFFImporter::TRIMESH);
458 }
else if (vertexCount == 0 && nF != 0) {
462 _importer.
addOption(OFFImporter::POLYMESH);
472 QFile theFile(_filename);
473 if ( !theFile.exists() ){
474 emit log(
LOGERR, tr(
"Unable to load OFF file. File not found!"));
485 std::ifstream ifile(_filename.toUtf8(), (_importer.isBinary() ? std::ios::binary | std::ios::in
488 unsigned long sz = theFile.size()/1024/1024;
490 if(sz <= 2 * Utils::Memory::queryFreeRAM())
492 ifile.rdbuf()->pubsetbuf(NULL,theFile.size());
495 if (!ifile.is_open() || !ifile.good())
497 emit log(
LOGERR, tr(
"Cannot open OFF file for reading!"));
503 int triMeshControl = TYPEAUTODETECT;
505 if ( OpenFlipper::Options::gui() ){
506 if ( triMeshHandling_ != 0 ){
507 triMeshControl = triMeshHandling_->currentIndex();
509 triMeshControl = TYPEAUTODETECT;
513 if ( forceTriangleMesh_ )
514 triMeshControl = TYPETRIANGLE;
516 if ( forcePolyMesh_ )
517 triMeshControl = TYPEPOLY;
521 switch (triMeshControl) {
528 if( !OpenFlipper::Options::nogui() ) {
530 QMetaObject::invokeMethod(
this,
"handleTrimeshDialog",Qt::BlockingQueuedConnection);
532 if (trimeshOptions_ == OFFImporter::TRIMESH)
534 else if (trimeshOptions_ == OFFImporter::POLYMESH)
561 return _importer.isBinary() ?
parseBinary(ifile, _importer, type, _filename) :
parseASCII(ifile, _importer, type, _filename);
567 QPushButton *detectButton = msgBox.addButton(tr(
"Auto-Detect"), QMessageBox::ActionRole);
568 QPushButton *triButton = msgBox.addButton(tr(
"Open as triangle mesh"), QMessageBox::ActionRole);
569 QPushButton *polyButton = msgBox.addButton(tr(
"Open as poly mesh"), QMessageBox::ActionRole);
570 msgBox.setWindowTitle( tr(
"Mesh types in file") );
571 msgBox.setText( tr(
"You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
572 msgBox.setDefaultButton( detectButton );
576 if (msgBox.clickedButton() == triButton)
577 trimeshOptions_ = OFFImporter::TRIMESH ;
578 else if (msgBox.clickedButton() == polyButton)
579 trimeshOptions_ = OFFImporter::POLYMESH ;
587 unsigned int nV, nF, dummy;
594 std::vector<VertexHandle> vhandles;
598 emit addEmptyObject(_type, objectId);
602 emit log(
LOGERR, tr(
"Could not create new object!"));
607 QFileInfo f(_objectName);
608 object->setName(f.fileName());
614 std::istringstream sstr;
629 _importer.reserve(nV, nF * _importer.maxFaceValence() , nF);
635 if ( (c ==
'\n') || (c ==
'#') )
636 std::getline(_in, tmp);
642 for (uint i=0; i<nV && !_in.eof(); ++i) {
645 v[0] = getFloat(_in);
646 v[1] = getFloat(_in);
647 v[2] = getFloat(_in);
649 const VertexHandle vh = _importer.
addVertex(v);
654 n[0] = getFloat(_in);
655 n[1] = getFloat(_in);
656 n[2] = getFloat(_in);
658 if(userReadOptions_ & OFFImporter::VERTEXNORMAL) {
668 int colorType =
getColorType(line, _importer.hasTextureCoords() );
671 if ( _importer.hasVertexColors() ){
677 case 1 : sstr >> trash;
break;
678 case 2 : sstr >> trash; sstr >> trash;
break;
684 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
685 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c3 ) );
695 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
696 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c4 ) );
698 _importer.
addOption(OFFImporter::COLORALPHA);
703 c3f[0] = getFloat(sstr);
704 c3f[1] = getFloat(sstr);
705 c3f[2] = getFloat(sstr);
706 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
707 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c3f) );
713 c4f[0] = getFloat(sstr);
714 c4f[1] = getFloat(sstr);
715 c4f[2] = getFloat(sstr);
716 c4f[3] = getFloat(sstr);
717 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
718 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c4f) );
720 _importer.
addOption(OFFImporter::COLORALPHA);
725 std::cerr <<
"Error in file format (colorType = " << colorType <<
")\n";
731 if ( _importer.hasTextureCoords() ){
732 t[0] = getFloat(sstr);
733 t[1] = getFloat(sstr);
734 if ( userReadOptions_ & OFFImporter::VERTEXTEXCOORDS ) {
744 if ( (c ==
'\n') || (c ==
'#') )
745 std::getline(_in, tmp);
752 for (uint i=0; i<nF; ++i)
767 for (uint i=0; i<nV; ++i) {
769 vhandles.push_back(VertexHandle(idx));
772 bool checkManifold =
true;
773 if(!OpenFlipper::Options::nogui() && loadCheckManifold_ != 0) {
774 checkManifold = loadCheckManifold_->isChecked();
780 fh = _importer.
addFace(vhandles);
785 fh = _importer.
addFace(vhandles);
789 if ( _importer.hasFaceColors() ){
802 case 1 : sstr >> trash;
break;
803 case 2 : sstr >> trash; sstr >> trash;
break;
809 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
810 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c3 ) );
820 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
821 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c4 ) );
823 _importer.
addOption(OFFImporter::COLORALPHA);
828 c3f[0] = getFloat(sstr);
829 c3f[1] = getFloat(sstr);
830 c3f[2] = getFloat(sstr);
831 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
832 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c3f) );
838 c4f[0] = getFloat(sstr);
839 c4f[1] = getFloat(sstr);
840 c4f[2] = getFloat(sstr);
841 c4f[3] = getFloat(sstr);
842 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
843 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c4f) );
845 _importer.
addOption(OFFImporter::COLORALPHA);
850 std::cerr <<
"Error in file format (colorType = " << colorType <<
")\n";
865 int size = _v.size();
867 for(
int i = 0; i < size; ++i) {
868 for(
int j = i+1; j < size; ++j) {
869 if(_v[i] == _v[j]) check =
false;
889 if ( _line.size() < 1 )
899 found=_line.find_first_of(
" ");
900 while (found!=std::string::npos){
902 found=_line.find_first_of(
" ",found+1);
905 if (!_line.empty()) count++;
907 if (_texCoordsAvailable) count -= 2;
909 if (count == 3 || count == 4){
911 found = _line.find(
" ");
912 std::string c1 = _line.substr (0,found);
914 if (c1.find(
".") != std::string::npos){
929 unsigned int nV, nF, dummy;
935 std::vector<VertexHandle> vhandles;
939 emit addEmptyObject(_type, objectId);
943 emit log(
LOGERR, tr(
"Could not create new object!"));
948 QFileInfo f(_objectName);
949 object->setName(f.fileName());
961 readValue(_in, dummy);
964 _importer.reserve(nV, nF * _importer.maxFaceValence() , nF);
967 for (uint i=0; i<nV && !_in.eof(); ++i)
970 readValue(_in, v[0]);
971 readValue(_in, v[1]);
972 readValue(_in, v[2]);
974 const VertexHandle vh = _importer.
addVertex(v);
977 readValue(_in, n[0]);
978 readValue(_in, n[1]);
979 readValue(_in, n[2]);
981 if ( userReadOptions_ & OFFImporter::VERTEXNORMAL ) {
987 if ( _importer.hasVertexColors() ) {
989 readValue(_in, c[0]);
990 readValue(_in, c[1]);
991 readValue(_in, c[2]);
994 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
1000 if ( _importer.hasTextureCoords() ) {
1001 readValue(_in, t[0]);
1002 readValue(_in, t[1]);
1004 if ( userReadOptions_ & OFFImporter::VERTEXTEXCOORDS ) {
1016 for (uint i = 0; i<nF && !_in.eof(); ++i)
1021 _in.seekg(0, std::ios::end);
1054 readColorComp_ =
false;
1069 for (uint j = 0; j < nV; ++j) {
1070 readValue(_in, dummy);
1074 if (readColorComp_) {
1077 for (uint j = 0; j < nV; ++j) {
1078 readValue(_in, dummy_f);
1087 for (uint j = 0; j < nV; ++j) {
1088 readValue(_in, idx);
1089 vhandles.push_back(VertexHandle(idx));
1092 fh = _importer.
addFace(vhandles);
1094 if ( !readColorComp_ ) {
1106 if ( nV == 3 || nV == 4 ) {
1109 for(uint k = 0; k < 3; ++k) {
1110 readValue(_in, c[k]);
1116 readValue(_in, alpha);
1119 if(userReadOptions_ & OFFImporter::FACECOLOR) {
1120 if(userReadOptions_ & OFFImporter::COLORALPHA) {
1123 _importer.
addOption(OFFImporter::COLORALPHA);
1125 int cidx = _importer.
addColor(OpenMesh::color_cast<OpenMesh::Vec4f>(c));
1131 for(uint i = 0; i < nV; ++i) {
1132 readValue(_in, dummy_f);
1164 int pos = _in.tellg();
1166 for(uint k = 0; k < _nF; ++k) {
1172 for(uint z = 0; z < nV; ++z) {
1173 readValue(_in, dummy);
1178 int currPos = _in.tellg();
1183 if(_nB - currPos == 0) {
1207 forceTriangleMesh_ =
false;
1208 forcePolyMesh_ =
false;
1213 object->setFromFileName(_filename);
1220 if ( !importer.
hasVertexNormals() || (userReadOptions_ & OFFImporter::FORCE_NONORMALS) ) {
1221 emit log(
LOGINFO, tr(
"loadObject: Computing vertex and face normals.") );
1224 emit log(
LOGINFO, tr(
"loadObject: Computing face normals.") );
1236 if ( !importer.
hasVertexNormals() || (userReadOptions_ & OFFImporter::FORCE_NONORMALS) ) {
1237 emit log(
LOGINFO, tr(
"loadObject: Computing vertex and face normals.") );
1240 emit log(
LOGINFO, tr(
"loadObject: Computing face normals.") );
1249 emit openedFile( object->
id() );
1251 forceTriangleMesh_ =
false;
1252 forcePolyMesh_ =
false;
1253 return object->id();
1260 forceTriangleMesh_ =
false;
1261 forcePolyMesh_ =
false;
1264 forceTriangleMesh_ =
true;
1266 forcePolyMesh_ =
true;
1274 bool FileOFFPlugin::saveObject(
int _id, QString _filename)
1278 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
1282 std::string filename = std::string( _filename.toUtf8() );
1284 bool binary = userWriteOptions_ & OFFImporter::BINARY;
1285 std::fstream ofs( filename.c_str(), (binary ? std::ios_base::out | std::ios_base::binary : std::ios_base::out));
1289 emit log(
LOGERR, tr(
"saveObject : Cannot not open file %1 for writing!").arg(_filename) );
1298 object->setFromFileName(_filename);
1299 object->setName(object->
filename());
1304 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
1308 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
1314 object->setFromFileName(_filename);
1315 object->setName(object->
filename());
1320 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
1324 emit log(
LOGERR, tr(
"Unable to save ") + _filename );
1329 emit log(
LOGERR, tr(
"Unable to save (object is not a compatible mesh type)"));
1337 template <
class MeshT>
1341 if (_mesh.has_vertex_texcoords2D()) {
1344 if (!_mesh.get_property_handle(oldVertexCoords,
"Original Per Vertex Texture Coords"))
1345 _mesh.add_property(oldVertexCoords,
"Original Per Vertex Texture Coords");
1347 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it)
1348 _mesh.property(oldVertexCoords, *v_it) = _mesh.texcoord2D(*v_it);
1353 if (_mesh.has_halfedge_texcoords2D()) {
1356 if (!_mesh.get_property_handle(oldHalfedgeCoords,
"Original Per Face Texture Coords"))
1357 _mesh.add_property(oldHalfedgeCoords,
"Original Per Face Texture Coords");
1359 for (
typename MeshT::HalfedgeIter he_it = _mesh.halfedges_begin(); he_it != _mesh.halfedges_end(); ++he_it)
1360 _mesh.property(oldHalfedgeCoords, *he_it) = _mesh.texcoord2D(*he_it);
1369 if (saveOptions_ == 0){
1371 saveOptions_ =
new QWidget();
1372 QVBoxLayout* layout =
new QVBoxLayout();
1373 layout->setAlignment(Qt::AlignTop);
1375 saveBinary_ =
new QCheckBox(
"Save Binary");
1376 layout->addWidget(saveBinary_);
1378 saveVertexColor_ =
new QCheckBox(
"Save Vertex Colors");
1379 layout->addWidget(saveVertexColor_);
1381 saveFaceColor_ =
new QCheckBox(
"Save Face Colors");
1382 layout->addWidget(saveFaceColor_);
1384 saveAlpha_ =
new QCheckBox(
"Save Color Alpha");
1385 layout->addWidget(saveAlpha_);
1387 saveNormals_ =
new QCheckBox(
"Save Normals");
1388 layout->addWidget(saveNormals_);
1390 saveTexCoords_ =
new QCheckBox(
"Save TexCoords");
1391 layout->addWidget(saveTexCoords_);
1393 savePrecisionLabel_ =
new QLabel(
"Writer Precision");
1394 layout->addWidget(savePrecisionLabel_);
1396 savePrecision_ =
new QSpinBox();
1397 savePrecision_->setMinimum(1);
1398 savePrecision_->setMaximum(12);
1399 savePrecision_->setValue(6);
1400 layout->addWidget(savePrecision_);
1402 saveDefaultButton_ =
new QPushButton(
"Make Default");
1403 layout->addWidget(saveDefaultButton_);
1405 saveOptions_->setLayout(layout);
1407 connect(saveBinary_, SIGNAL(clicked(
bool)), savePrecision_, SLOT(setDisabled(
bool)));
1408 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
1410 saveBinary_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/Binary",
false).toBool() );
1411 saveVertexColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/VertexColor",
true).toBool() );
1412 saveFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/FaceColor",
true).toBool() );
1413 saveAlpha_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/Alpha",
true).toBool() );
1414 saveNormals_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/Normals",
true).toBool() );
1415 saveTexCoords_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/TexCoords",
true).toBool() );
1419 return saveOptions_;
1426 if (loadOptions_ == 0){
1428 loadOptions_ =
new QWidget();
1429 QVBoxLayout* layout =
new QVBoxLayout();
1430 layout->setAlignment(Qt::AlignTop);
1432 QLabel* label =
new QLabel(tr(
"If PolyMesh is a Triangle Mesh:"));
1434 layout->addWidget(label);
1436 triMeshHandling_ =
new QComboBox();
1437 triMeshHandling_->addItem( tr(
"Auto-Detect") );
1438 triMeshHandling_->addItem( tr(
"Ask") );
1439 triMeshHandling_->addItem( tr(
"Always open as PolyMesh") );
1440 triMeshHandling_->addItem( tr(
"Always open as TriangleMesh") );
1442 layout->addWidget(triMeshHandling_);
1444 loadVertexColor_ =
new QCheckBox(
"Load Vertex Colors");
1445 layout->addWidget(loadVertexColor_);
1447 loadFaceColor_ =
new QCheckBox(
"Load Face Colors");
1448 layout->addWidget(loadFaceColor_);
1450 loadAlpha_ =
new QCheckBox(
"Load Color Alpha");
1451 layout->addWidget(loadAlpha_);
1453 loadNormals_ =
new QCheckBox(
"Load Normals");
1454 layout->addWidget(loadNormals_);
1456 loadTexCoords_ =
new QCheckBox(
"Load TexCoords");
1457 layout->addWidget(loadTexCoords_);
1459 loadCheckManifold_ =
new QCheckBox(
"Check for manifold configurations");
1460 layout->addWidget(loadCheckManifold_);
1462 loadDefaultButton_ =
new QPushButton(
"Make Default");
1463 layout->addWidget(loadDefaultButton_);
1465 loadOptions_->setLayout(layout);
1467 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
1469 triMeshHandling_->setCurrentIndex(
OpenFlipperSettings().value(
"FileOff/Load/TriMeshHandling",TYPEAUTODETECT ).toInt() );
1471 loadVertexColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/VertexColor",
true).toBool() );
1472 loadFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/FaceColor",
true).toBool() );
1473 loadAlpha_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/Alpha",
true).toBool() );
1474 loadNormals_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/Normals",
true).toBool() );
1475 loadTexCoords_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/TexCoords",
true).toBool() );
1478 return loadOptions_;
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getCleanLine(std::istream &ifs, std::string &_string, bool _skipEmptyLines=true)
Function to retrieve next line.
BaseObject * getObject()
get BaseObject data of object
bool hasVertexNormals()
Query Object Options.
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
int addNormal(const Vec3f &_normal)
add a normal
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
bool dataType(DataType _type) const
MeshT * mesh()
return a pointer to the mesh
bool parseASCII(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse ascii OFF file.
bool readOFFFile(QString _filename, OFFImporter &_importer)
Read OFF file and parse it.
bool readFileOptions(QString _filename, OFFImporter &_importer)
Before Parsing the actual file, read all features supported.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Type for a MeshObject containing a triangle mesh.
void addObject(BaseObject *_object)
add initial object
QWidget * saveOptionsWidget(QString)
QString filename() const
return the filename of the object
void setNormal(VertexHandle _vh, int _normalID)
set vertex normal
QWidget * loadOptionsWidget(QString)
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
bool checkDegenerateFace(const std::vector< VertexHandle > &_v)
Check for degenerate faces before adding them.
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
FileOFFPlugin()
Constructor.
void backupTextureCoordinates(MeshT &_mesh)
backup per vertex/face texture coordinates
void setVertexColor(VertexHandle _vh, int _colorIndex)
set vertex color
bool extendedFaceColorTest(std::istream &_in, uint _nV, uint _nF, int _nB) const
Test if there are face color components (_nV is the initial face valence)
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.
void initializePlugin()
Initialize Plugin.
int addTexCoord(const Vec2f &_coord)
add texture coordinates
bool parseBinary(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse binary OFF file.
VertexHandle addVertex(const Vec3f &_point)
add a vertex with coordinate _point
int addColor(const Vec4f &_color)
add a color
void update_face_normals()
Update normal vectors for all faces.
void addOption(ObjectOptionsE _option)
add an option
#define DATA_TRIANGLE_MESH
int addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
void removeOption(ObjectOptionsE _option)
remove an option
Type for a Meshobject containing a poly mesh.
void update_normals()
Compute normals for all primitives.
void setFaceColor(FaceHandle _fh, int _colorIndex)
set face color
int getColorType(std::string &_line, bool _texCoordsAvailable)
Get color type.