/* Write out all triangles in an object */ void print_object(object * obj, int level, dimeModel & model, const char * layername, dimeBlock * block) { int i; const dimeLayer * layer = model.getLayer(layername); for (i = 0; i < obj->npoly; i++) { print_triangle(&obj->poly[i], model, layer, block); } }
void MeshDXF::traverseEntitiesCounting(dimeModel &model) { dimeEntitiesSection *entities = (dimeEntitiesSection*) model.findSection("ENTITIES"); if(entities == NULL) return; dimeEntity *tempEntity; for(int i=0; i<entities->getNumEntities(); i++) { tempEntity = entities->getEntity(i); if( strcmp(tempEntity->getEntityName(),"3DFACE")==0 ) tempIndex +=4; if( strcmp(tempEntity->getEntityName(),"POLYLINE")==0 ) countPolylineEntity(tempEntity); } }
/*! Finds the state of supported header variables in \a model. This method should be called before dxfxConverter::doConvert() */ void dxfConverter::findHeaderVariables(dimeModel &model) { dimeHeaderSection *hs = (dimeHeaderSection*) model.findSection("HEADER"); if (hs) { dimeParam param; int groupcode; if (hs->getVariable("$FILLMODE", &groupcode, ¶m, 1) == 1) { if (groupcode == 70) this->fillmode = (bool) param.int16_data; } } }
/*! Converts \a model to the internal geometry structures. \sa dxfConverter::writeWrl() */ bool dxfConverter::doConvert(dimeModel &model) { // // remove these 6 lines, and you may merge several dxf // files into a single vrml file by calling doConvert() several // times before calling writeVrml // for (int i = 0; i < 255; i++) { if (layerData[i]) { delete layerData[i]; layerData[i] = NULL; } } return model.traverseEntities(dime_callback, this, false, true, false); }
void MeshDXF::traverseBlocksProcessing(dimeModel &model) { dimeBlocksSection *blocks = (dimeBlocksSection*) model.findSection("BLOCKS"); if(blocks == NULL) return; dimeBlock *tempBlock; dimeEntity *tempEntity; for(int i=0; i<blocks->getNumBlocks();i++) { tempBlock = blocks->getBlock(i); for(int j=0; j<tempBlock->getNumEntities(); j++) { tempEntity = tempBlock->getEntity(j); if( strcmp(tempEntity->getEntityName(),"3DFACE")==0 ) process3DFaceEntity(tempEntity); if( strcmp(tempEntity->getEntityName(),"POLYLINE")==0 ) processPolylineEntity(tempEntity); } } }
void MeshDXF::traverseBlocksCounting(dimeModel &model) { dimeBlocksSection *blocks = (dimeBlocksSection*) model.findSection("BLOCKS"); if(blocks == NULL) return; dimeBlock *tempBlock; dimeEntity *tempEntity; for(int i=0; i<blocks->getNumBlocks();i++) { tempBlock = blocks->getBlock(i); for(int j=0; j<tempBlock->getNumEntities(); j++) { tempEntity = tempBlock->getEntity(j); if( strcmp(tempEntity->getEntityName(),"3DFACE")==0 ) tempIndex +=4; if( strcmp(tempEntity->getEntityName(),"POLYLINE")==0 ) countPolylineEntity(tempEntity); //printf("%s\n",tempEntity->getEntityName()); } } }
/* Output a triangle */ void print_triangle(triangle * t, dimeModel & model, const dimeLayer * layer, dimeBlock * block) { #if defined(DXFSPHERE_FILLED) && !defined(DXFSPHERE_USE_UNKNOWNENTITY) // filled, create dime3DFace int i; // DIME: create a 3DFACE entity, and set it to contain a triangle dime3DFace * face = new dime3DFace; if (layer) { face->setLayer(layer); } dimeVec3f v[3]; for (i = 0; i < 3; i++) { v[i].x = t->pt[i].x; v[i].y = t->pt[i].y; v[i].z = t->pt[i].z; } face->setTriangle(v[0], v[1], v[2]); // DIME: create a unique handle for this entity. const int BUFSIZE = 1024; char buf[BUFSIZE]; const char * handle = model.getUniqueHandle(buf, BUFSIZE); dimeParam param; param.string_data = handle; face->setRecord(5, param); // DIME: add entity to model if (block) { block->insertEntity(face); } else { model.addEntity(face); } #elif defined(DXFSPHERE_USE_UNKNOWNENTITY) // DIME: create a dimeUnknownEntity, and set it to contain a triangle dimeUnknownEntity * face = new dimeUnknownEntity("3DFACE", NULL); if (layer) { face->setLayer(layer); } dimeParam param; // 10,20,30 is the first vertex // 11,21,31 is the second vertex // 12,22,32 is the third vertex for (int i = 0; i < 3; i++) { param.double_data = t->pt[i].x; face->setRecord(i + 10, param); param.double_data = t->pt[i].y; face->setRecord(i + 20, param); param.double_data = t->pt[i].z; face->setRecord(i + 30, param); } // to make 3DFACE contain a triangle and not a quad, the fourth // vertex must be equal to the third. We therefore iterate from 0 to // 4, but clamp the index when fetching the vertex from the triangle // structure. param.double_data = t->pt[2].x; face->setRecord(13, param); param.double_data = t->pt[2].y; face->setRecord(23, param); param.double_data = t->pt[2].z; face->setRecord(33, param); // DIME: create a unique handle for this entity. const int BUFSIZE = 1024; char buf[BUFSIZE]; const char * handle = model.getUniqueHandle(buf, BUFSIZE); param.string_data = handle; face->setRecord(5, param); // DIME: add entity to model model.addEntity(face); #else // create three dimeLine entities to represent the triangle int i; for (i = 0; i < 3; i++) { // DIME: create a LINE entity dimeLine * line = new dimeLine; if (layer) { line->setLayer(layer); } dimeVec3f v[2]; v[0].x = t->pt[i].x; v[0].y = t->pt[i].y; v[0].z = t->pt[i].z; v[1].x = t->pt[(i+1)%3].x; v[1].y = t->pt[(i+1)%3].y; v[1].z = t->pt[(i+1)%3].z; line->setCoords(0, v[0]); line->setCoords(1, v[1]); // DIME: create unique handle for the entity (needed to load the file into AutoCAD) const int BUFSIZE = 1024; char buf[BUFSIZE]; const char * handle = model.getUniqueHandle(buf, BUFSIZE); dimeParam param; param.string_data = handle; line->setRecord(5, param); // DIME: add entity to model if (block) { block->insertEntity(line); } else { model.addEntity(line); } } #endif // ! DXFSPHERE_FILLED }