Ignore:
Timestamp:
12/11/20 20:23:42 (3 months ago)
Author:
oriona
Message:

Part of GeometryTestUtils? functions moved to GeometryUtils?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/geometry/geometryutils.cpp

    r1032 r1045  
    44
    55#include "geometryutils.h"
    6 
    76#include <math.h>
    87
     
    409408        return true;
    410409}
     410
     411void 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
     422void 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
     434void GeometryUtils::addAxesToModel(const Pt3D &sizes, const Orient &axes, const Pt3D &center,
     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
     462void 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
     472double frand(double from, double width)
     473{
     474    return from + width * ((rand() % 10000) / 10000.0);
     475}
     476
     477void 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}
Note: See TracChangeset for help on using the changeset viewer.