Changeset 1045 for cpp/frams/model
- Timestamp:
- 12/11/20 20:23:42 (4 years ago)
- Location:
- cpp/frams/model
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/geometry/geometryutils.cpp
r1032 r1045 4 4 5 5 #include "geometryutils.h" 6 7 6 #include <math.h> 8 7 … … 409 408 return true; 410 409 } 410 411 void GeometryUtils::addAnchorToModel(Model &model) 412 { 413 Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID); 414 415 part->p = Pt3D(0); 416 part->scale = Pt3D(0.1); 417 part->vcolor = Pt3D(1.0, 0.0, 1.0); 418 419 addAxesToModel(Pt3D(0.5), Orient(Orient_1), Pt3D(0.0), model); 420 } 421 422 void GeometryUtils::addPointToModel(const Pt3D &markerLocation, Model &model) 423 { 424 Part *anchor = model.getPart(0); 425 Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID); 426 427 part->p = Pt3D(markerLocation); 428 part->scale = Pt3D(0.05); 429 part->vcolor = Pt3D(1.0, 1.0, 0.0); 430 431 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 432 } 433 434 void GeometryUtils::addAxesToModel(const Pt3D &sizes, const Orient &axes, const Pt3D ¢er, 435 Model &model) 436 { 437 Part *anchor = model.getPart(0); 438 Part *part; 439 440 part = model.addNewPart(Part::SHAPE_CUBOID); 441 part->scale = Pt3D(sizes.x, 0.05, 0.05); 442 part->setOrient(axes); 443 part->p = center; 444 part->vcolor = Pt3D(1.0, 0.0, 0.0); 445 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 446 447 part = model.addNewPart(Part::SHAPE_CUBOID); 448 part->scale = Pt3D(0.05, sizes.y, 0.05); 449 part->setOrient(axes); 450 part->p = center; 451 part->vcolor = Pt3D(0.0, 1.0, 0.0); 452 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 453 454 part = model.addNewPart(Part::SHAPE_CUBOID); 455 part->scale = Pt3D(0.05, 0.05, sizes.z); 456 part->setOrient(axes); 457 part->p = center; 458 part->vcolor = Pt3D(0.0, 0.0, 1.0); 459 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 460 } 461 462 void GeometryUtils::mergeModels(Model &target, Model &source) 463 { 464 Part *targetAnchor = target.getPart(0); 465 Part *sourceAnchor = source.getPart(0); 466 467 target.moveElementsFrom(source); 468 469 target.addNewJoint(targetAnchor, sourceAnchor, Joint::SHAPE_FIXED); 470 } 471 472 double frand(double from, double width) 473 { 474 return from + width * ((rand() % 10000) / 10000.0); 475 } 476 477 void GeometryUtils::randomizePositionScaleAndOrient(Part *part) 478 { 479 part->p = Pt3D(frand(1.5, 1.0), frand(1.5, 1.0), frand(1.5, 1.0)); 480 part->scale = Pt3D(frand(0.1, 0.9), frand(0.1, 0.9), frand(0.1, 0.9)); 481 part->setRot(Pt3D(frand(0.0, M_PI), frand(0.0, M_PI), frand(0.0, M_PI))); 482 } -
cpp/frams/model/geometry/geometryutils.h
r1032 r1045 180 180 double calculateSolidVolume(Part *part); 181 181 bool isSolidPartScaleValid(const Part::Shape &partShape, const Pt3D &scale); 182 183 /** 184 * @brief Adds anchor to the specified Model. 185 * @details An anchor has two functions. First is to provide Model consistency. Some functions in 186 * GeometryTestUtils namespace requires Model passed to them as an argument to contain at 187 * least one Part. All new Parts are bonded to the rest of Model using Joint connecting them 188 * with first Part of Model. Second is to provide reference which helps to understand Model 189 * position, scale and orientation. Anchor is built from four Parts: small sphere placed in 190 * global coordinate system origin and three cuboids visualising global coordinate system 191 * axes. 192 * @see addAxesToModel. 193 * @param[in] model Owner of Parts to be created. 194 */ 195 void addAnchorToModel(Model &model); 196 197 /** 198 * @brief Adds point marker to Model. 199 * @details Marker of point is a small sphere (radius = 0.05). 200 * @param[in] point Location of marker. 201 * @param[in] model Owner of Part to be created, must contain at least one part. 202 */ 203 void addPointToModel(const Pt3D &point, Model &model); 204 205 /** 206 * @brief Adds axes markers to Model. 207 * @details Axes markers are three streched (one of scales = 0.5, others = 0.05) and colored 208 * cuboids. Cuboid visualising OX axis is red, OY - green, and OZ - blue. 209 * @param[in] sizes Axes visual lengths. 210 * @param[in] axes Axes orientation, relatively to global coordinate system axes. 211 * @param[in] center Axes intersection point, relatively to global coordinate system origin. 212 * @param[in] model Owner of Parts to be created, must contain at least one part. 213 */ 214 void addAxesToModel(const Pt3D &sizes, const Orient &axes, const Pt3D ¢er, Model &model); 215 216 /** 217 * @brief Merges two Models. 218 * @details Moves all parts from source Model to target Model and - to provide Model 219 * consistency - creates Joint between firsts Parts of each of them. Each model must contain 220 * at least one Part. 221 * @param[in] target Target Model, must contain at least one part. 222 * @param[in] source Source Model, must contain at least one part. 223 */ 224 void mergeModels(Model &target, Model &source); 225 226 /** 227 * @brief Randomizes position, scale and rotations of Part. 228 * @details Sets coords of Part position to random values from range (1.5, 2.5), scales to 229 * random values from range (0.1, 1.0), and rotations around each axis to random values from 230 * range (0, M_PI). 231 * @param[in] part Part which position, scale and orient should be randomized. 232 */ 233 void randomizePositionScaleAndOrient(Part *part); 182 234 } 183 235 -
cpp/frams/model/similarity/simil-measure.cpp
r1044 r1045 5 5 #include "simil-measure.h" 6 6 #include <frams/vm/classes/genoobj.h> 7 #include <frams/model/geometry/geometryutils.h> 7 8 #include <frams/model/geometry/meshbuilder.h> 8 #include <frams/_demos/geometry/geometrytestutils.h>9 9 10 10 #define FIELDSTRUCT SimilMeasure … … 81 81 Model resultModel; 82 82 resultModel.open(); 83 Geometry TestUtils::addAnchorToModel(resultModel);83 GeometryUtils::addAnchorToModel(resultModel); 84 84 85 85 MeshBuilder::ModelSurface iterator(density); … … 89 89 while (iterator.tryGetNext(point)) 90 90 { 91 Geometry TestUtils::addPointToModel(point, resultModel);91 GeometryUtils::addPointToModel(point, resultModel); 92 92 } 93 93
Note: See TracChangeset
for help on using the changeset viewer.