Changeset 546 for cpp/frams


Ignore:
Timestamp:
07/28/16 03:39:26 (8 years ago)
Author:
Maciej Komosinski
Message:

Renamed: Model::buildUsingNewShapes -> Model::buildUsingSolidShapeTypes()
Added class SolidsShapeTypeModel? (for making ball-and-stick Models look like solids-type Models)
ModelGeometryInfo? functions: findSizesAndAxesOfModel(), volume() and area() now accept ball-and-stick Models (using SolidsShapeTypeModel? class)
[refs #46] and possibly closes this issue (needs verification)

Location:
cpp/frams
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/shapeconvert.cpp

    r544 r546  
    8383        Model newmodel;
    8484        newmodel.open();
    85         newmodel.buildUsingNewShapes(m, shape, thickness);
     85        newmodel.buildUsingSolidShapeTypes(m, shape, thickness);
    8686        newmodel.close();
    8787
  • cpp/frams/model/geometry/modelgeometryinfo.cpp

    r375 r546  
    77#include <frams/model/geometry/meshbuilder.h>
    88
    9 void ModelGeometryInfo::findSizesAndAxesOfModel(const Model &model, const double density,
     9void ModelGeometryInfo::findSizesAndAxesOfModel(const Model &input_model, const double density,
    1010        Pt3D &sizes, Orient &axes)
    1111{
     12        SolidsShapeTypeModel model(input_model);
    1213        SListTempl<Pt3D> points;
    1314        MeshBuilder::ModelApices apices(density);
    14         apices.initialize(&model);
     15        apices.initialize(&model.getModel());
    1516        apices.addAllPointsToList(points);
    1617        if (points.size() < 1) //maybe 1 or 2 points are also not enough for findSizesAndAxesOfPointsGroup() to work...
    1718        {
    18                 logPrintf("ModelGeometryInfo", "findSizesAndAxesOfModel", LOG_ERROR, "Empty points sample for model with %d part(s)", model.getPartCount());
     19                logPrintf("ModelGeometryInfo", "findSizesAndAxesOfModel", LOG_ERROR, "Empty points sample for model with %d part(s)", model.getModel().getPartCount());
    1920                sizes = Pt3D_0;
    2021                axes = Orient_1;
     
    6566}
    6667
    67 double ModelGeometryInfo::volume(const Model &model, const double density)
     68double ModelGeometryInfo::volume(const Model &input_model, const double density)
    6869{
     70        SolidsShapeTypeModel model(input_model);
    6971        Pt3D lowerBoundary, upperBoundary;
    7072        boundingBox(model, lowerBoundary, upperBoundary);
     
    9092}
    9193
    92 double ModelGeometryInfo::area(const Model &model, const double density)
     94double ModelGeometryInfo::area(const Model &input_model, const double density)
    9395{
     96        SolidsShapeTypeModel model(input_model);
    9497        double area = 0.0;
    9598       
    96         for (int partIndex = 0; partIndex < model.getPartCount(); partIndex+=1)
     99        for (int partIndex = 0; partIndex < model.getModel().getPartCount(); partIndex+=1)
    97100        {
    98101                area += externalAreaOfPart(model, partIndex, density);
  • cpp/frams/model/model.cpp

    r544 r546  
    973973                                j->p2_refno = j->part2->refno;
    974974                                if (checklevel > 0)
    975                                         {
     975                                {
    976976                                        j->part1->mass += 1.0;
    977977                                        j->part2->mass += 1.0;
    978                                         }
     978                                }
    979979                                if ((j->usedelta) && ((j->d.x != JOINT_DELTA_MARKER) || (j->d.y != JOINT_DELTA_MARKER) || (j->d.z != JOINT_DELTA_MARKER)))
    980980                                { // delta positioning -> calc. orient.
     
    13361336}
    13371337
    1338 void Model::buildUsingNewShapes(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);
     1338void 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);
    13441344                p->p = (oj->part1->p + oj->part2->p) / 2;
    13451345                Orient o;
     
    13501350                p->scale.z = thickness;
    13511351        }
    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);
    13581358                        if ((oj->part1 == op) || (oj->part2 == op))
    13591359                        {
    1360                                 for (int j2 = j + 1; j2 < old.getJointCount(); j2++)
     1360                                for (int j2 = j + 1; j2 < src_ballandstick_shapes.getJointCount(); j2++)
    13611361                                {
    1362                                         Joint *oj2 = old.getJoint(j2);
     1362                                        Joint *oj2 = src_ballandstick_shapes.getJoint(j2);
    13631363                                        if ((oj2->part1 == op) || (oj2->part2 == op))
    13641364                                        {
     
    13691369                        }
    13701370                }
     1371        }
     1372}
     1373
     1374SolidsShapeTypeModel::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;
    13711389        }
    13721390}
  • cpp/frams/model/model.h

    r544 r546  
    414414        void rotate(const Pt3D& angles) { Orient o = Orient_1; o.rotate(angles); rotate(o); }
    415415
    416         /// build this model using new shapes, based on the provided model that uses old shapes. See also shapeconvert.cpp.
    417         void buildUsingNewShapes(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 ball-and-stick model. See also shapeconvert.cpp.
     417        void buildUsingSolidShapeTypes(const Model& src_ballandstick_shapes, Part::Shape use_shape = Part::SHAPE_CYLINDER, float thickness = 0.2);
    418418
    419419#ifdef EASYMAPDEBUG
     
    448448};
    449449
     450/**
     451   An object of this class is created from a Model and returns the solids-type const Model& regardless of the source Model shape type.
     452   For solids-type Models, the same source Model reference is returned.
     453   For ball-and-stick-type Models, the new temporary Model is created (using Model::buildUsingSolidShapeTypes).
     454   Useful for making the solids-only code work for both solids Models and ball-and-stick 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 solids-type 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 */
     463class SolidsShapeTypeModel
     464{
     465public:
     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
    450474#endif
Note: See TracChangeset for help on using the changeset viewer.