Changeset 546
 Timestamp:
 07/28/16 03:39:26 (8 years ago)
 Location:
 cpp/frams
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/_demos/shapeconvert.cpp
r544 r546 83 83 Model newmodel; 84 84 newmodel.open(); 85 newmodel.buildUsing NewShapes(m, shape, thickness);85 newmodel.buildUsingSolidShapeTypes(m, shape, thickness); 86 86 newmodel.close(); 87 87 
cpp/frams/model/geometry/modelgeometryinfo.cpp
r375 r546 7 7 #include <frams/model/geometry/meshbuilder.h> 8 8 9 void ModelGeometryInfo::findSizesAndAxesOfModel(const Model & model, const double density,9 void ModelGeometryInfo::findSizesAndAxesOfModel(const Model &input_model, const double density, 10 10 Pt3D &sizes, Orient &axes) 11 11 { 12 SolidsShapeTypeModel model(input_model); 12 13 SListTempl<Pt3D> points; 13 14 MeshBuilder::ModelApices apices(density); 14 apices.initialize(&model );15 apices.initialize(&model.getModel()); 15 16 apices.addAllPointsToList(points); 16 17 if (points.size() < 1) //maybe 1 or 2 points are also not enough for findSizesAndAxesOfPointsGroup() to work... 17 18 { 18 logPrintf("ModelGeometryInfo", "findSizesAndAxesOfModel", LOG_ERROR, "Empty points sample for model with %d part(s)", model.get PartCount());19 logPrintf("ModelGeometryInfo", "findSizesAndAxesOfModel", LOG_ERROR, "Empty points sample for model with %d part(s)", model.getModel().getPartCount()); 19 20 sizes = Pt3D_0; 20 21 axes = Orient_1; … … 65 66 } 66 67 67 double ModelGeometryInfo::volume(const Model & model, const double density)68 double ModelGeometryInfo::volume(const Model &input_model, const double density) 68 69 { 70 SolidsShapeTypeModel model(input_model); 69 71 Pt3D lowerBoundary, upperBoundary; 70 72 boundingBox(model, lowerBoundary, upperBoundary); … … 90 92 } 91 93 92 double ModelGeometryInfo::area(const Model & model, const double density)94 double ModelGeometryInfo::area(const Model &input_model, const double density) 93 95 { 96 SolidsShapeTypeModel model(input_model); 94 97 double area = 0.0; 95 98 96 for (int partIndex = 0; partIndex < model.get PartCount(); partIndex+=1)99 for (int partIndex = 0; partIndex < model.getModel().getPartCount(); partIndex+=1) 97 100 { 98 101 area += externalAreaOfPart(model, partIndex, density); 
cpp/frams/model/model.cpp
r544 r546 973 973 j>p2_refno = j>part2>refno; 974 974 if (checklevel > 0) 975 975 { 976 976 j>part1>mass += 1.0; 977 977 j>part2>mass += 1.0; 978 978 } 979 979 if ((j>usedelta) && ((j>d.x != JOINT_DELTA_MARKER)  (j>d.y != JOINT_DELTA_MARKER)  (j>d.z != JOINT_DELTA_MARKER))) 980 980 { // delta positioning > calc. orient. … … 1336 1336 } 1337 1337 1338 void Model::buildUsing NewShapes(const Model& old, Part::Shape default_shape, float thickness)1339 { 1340 for (int i = 0; i < old.getJointCount(); i++)1341 { 1342 Joint *oj = old.getJoint(i);1343 Part *p = addNewPart( default_shape);1338 void Model::buildUsingSolidShapeTypes(const Model& src_ballandstick_shapes, Part::Shape use_shape, float thickness) 1339 { 1340 for (int i = 0; i < src_ballandstick_shapes.getJointCount(); i++) 1341 { 1342 Joint *oj = src_ballandstick_shapes.getJoint(i); 1343 Part *p = addNewPart(use_shape); 1344 1344 p>p = (oj>part1>p + oj>part2>p) / 2; 1345 1345 Orient o; … … 1350 1350 p>scale.z = thickness; 1351 1351 } 1352 for (int i = 0; i < old.getPartCount(); i++)1353 { 1354 Part *op = old.getPart(i);1355 for (int j = 0; j < old.getJointCount(); j++)1356 { 1357 Joint *oj = old.getJoint(j);1352 for (int i = 0; i < src_ballandstick_shapes.getPartCount(); i++) 1353 { 1354 Part *op = src_ballandstick_shapes.getPart(i); 1355 for (int j = 0; j < src_ballandstick_shapes.getJointCount(); j++) 1356 { 1357 Joint *oj = src_ballandstick_shapes.getJoint(j); 1358 1358 if ((oj>part1 == op)  (oj>part2 == op)) 1359 1359 { 1360 for (int j2 = j + 1; j2 < old.getJointCount(); j2++)1360 for (int j2 = j + 1; j2 < src_ballandstick_shapes.getJointCount(); j2++) 1361 1361 { 1362 Joint *oj2 = old.getJoint(j2);1362 Joint *oj2 = src_ballandstick_shapes.getJoint(j2); 1363 1363 if ((oj2>part1 == op)  (oj2>part2 == op)) 1364 1364 { … … 1369 1369 } 1370 1370 } 1371 } 1372 } 1373 1374 SolidsShapeTypeModel::SolidsShapeTypeModel(const Model& m, Part::Shape use_shape, float thickness) 1375 { 1376 using_model = converted_model = NULL; 1377 if (m.getShapeType() == Model::SHAPE_BALL_AND_STICK) 1378 { 1379 converted_model = new Model; 1380 converted_model>open(); 1381 converted_model>buildUsingSolidShapeTypes(m, use_shape, thickness); 1382 converted_model>close(); 1383 using_model = converted_model; 1384 } 1385 else 1386 { 1387 converted_model = NULL; 1388 using_model = &m; 1371 1389 } 1372 1390 } 
cpp/frams/model/model.h
r544 r546 414 414 void rotate(const Pt3D& angles) { Orient o = Orient_1; o.rotate(angles); rotate(o); } 415 415 416 /// build this model using new shapes, based on the provided model that uses old shapes. See also shapeconvert.cpp.417 void buildUsing NewShapes(const Model& src_old_shapes, Part::Shape default_shape = Part::SHAPE_CYLINDER, float thickness = 0.2);416 /// build this model using solid shape types, based on the provided ballandstick model. See also shapeconvert.cpp. 417 void buildUsingSolidShapeTypes(const Model& src_ballandstick_shapes, Part::Shape use_shape = Part::SHAPE_CYLINDER, float thickness = 0.2); 418 418 419 419 #ifdef EASYMAPDEBUG … … 448 448 }; 449 449 450 /** 451 An object of this class is created from a Model and returns the solidstype const Model& regardless of the source Model shape type. 452 For solidstype Models, the same source Model reference is returned. 453 For ballandsticktype Models, the new temporary Model is created (using Model::buildUsingSolidShapeTypes). 454 Useful for making the solidsonly code work for both solids Models and ballandstick Models, without if's and special cases, like in this example: 455 456 void fun(const Model& input) // 'input' can be any shape type 457 { 458 SolidsShapeTypeModel converted(input); // 'converted' contains either 'input' or the new solidstype Model created from 'input' 459 functionAcceptingSolidsTypeModel(converted); // operator const Model&() is called automatically because of the function signature 460 int n=converted.getModel().getPartCount(); // getting the const Model& explicitly (converted.getPartCount() would fail) 461 } 462 */ 463 class SolidsShapeTypeModel 464 { 465 public: 466 Model *converted_model; 467 const Model *using_model; 468 SolidsShapeTypeModel(const Model& m, Part::Shape use_shape = Part::SHAPE_CYLINDER, float thickness = 0.2); 469 operator const Model&() const { return *using_model; } 470 const Model& getModel() const { return *using_model; } 471 ~SolidsShapeTypeModel() { if (converted_model) delete converted_model; } 472 }; 473 450 474 #endif
Note: See TracChangeset
for help on using the changeset viewer.