source: cpp/frams/_demos/geometry/info_test.cpp @ 1139

Last change on this file since 1139 was 1045, checked in by oriona, 4 years ago

Part of GeometryTestUtils? functions moved to GeometryUtils?.

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include "geometrytestutils.h"
6#include <frams/model/geometry/geometryutils.h>
7#include <frams/model/geometry/modelgeometryinfo.h>
8#include <frams/model/model.h>
9#include <frams/util/3d.h>
10#include <stdio.h>
11
12void test(Model &model, const double density)
13{
14        // EXAMPLES ------------------------------------------------------------------------------------
15       
16        // Calculating approximate volume of model. Parameter density describes minimal number of points
17        // created for each unit of length. It means, that for each cubic unit of bounding box of model,
18        // at least density^3 points will be created.
19        double volume = ModelGeometryInfo::volume(model, density);
20       
21       
22        // Calculating approximate surface area of model. Parameter density describes minimal number of
23        // points created for each unit of length. It means, that for each square unit of surface area
24        // of parts of model, at least density^2 points will be created.
25        double area = ModelGeometryInfo::area(model, density);
26       
27       
28        // Creating output variables.
29        Pt3D sizes;
30        Orient axes;
31        // Calculating approximate sizes and axes of model. These values are calculated together because
32        // they depend on each other. Sizes are distances between furthest points on model surface
33        // measured along corresponding axes. Fields sizes.x and axes.x describes the 'length' of 3D
34        // model. Fields sizes.y and axes.y desctibes 'width' of 2D model created by projecting original
35        // 3D model onto plane defined by axes.x vector. Fields sizes.z and axes.z destribes 'height' of
36        // model. Axes are perpendicular to each other. Parameter density describes minimal number of
37        // points created for each unit of length. It means, that for each square unit of surface area
38        // of parts of model, at least density^2 points will be created.
39        ModelGeometryInfo::findSizesAndAxes(model, density, sizes, axes);
40       
41       
42        // Creating output variables.
43        Pt3D lowerBoundary, upperBoundary;
44        // Calculating bounding box of model. Result is stored in variables lowerBoundary and
45        // upperBoundary.
46        ModelGeometryInfo::boundingBox(model, lowerBoundary, upperBoundary);
47       
48        // PRINTING RESULT -----------------------------------------------------------------------------
49       
50        // Creating and preparing result Model object.
51        Model resultModel;
52        resultModel.open();
53        GeometryUtils::addAnchorToModel(resultModel);
54       
55        // Adding bounding markers of bounding box apices.
56        for (Octants::Octant o = Octants::FIRST; o < Octants::NUMBER; o = Octants::Octant(o+1))
57        {
58                Pt3D apex;
59                apex.x = Octants::isPositiveX(o) ? upperBoundary.x : lowerBoundary.x;
60                apex.y = Octants::isPositiveY(o) ? upperBoundary.y : lowerBoundary.y;
61                apex.z = Octants::isPositiveZ(o) ? upperBoundary.z : lowerBoundary.z;
62                GeometryUtils::addPointToModel(apex, resultModel);
63        }
64       
65        // Adding markers of axes (intersection of axes is in the center of bounding box).
66        Pt3D intersection = (lowerBoundary + upperBoundary) * 0.5;
67        GeometryUtils::addAxesToModel(sizes, axes, intersection, resultModel);
68       
69        // Merging with original model.
70        GeometryUtils::mergeModels(resultModel, model);
71       
72        // Finishing result Model and printing its genotype.
73        resultModel.close();
74        puts(resultModel.getF0Geno().getGenesAndFormat().c_str());
75       
76        // Printing calculated values.
77        printf("# volume=%f\n", volume);
78        printf("# area=%f\n", area);
79        printf("# sizes.x=%f sizes.y=%f sizes.z=%f\n", sizes.x, sizes.y, sizes.z);
80        printf("# axes.x=(%f, %f, %f)\n", axes.x.x, axes.x.y, axes.x.z);
81        printf("# axes.y=(%f, %f, %f)\n", axes.y.x, axes.y.y, axes.y.z);
82        printf("# axes.z=(%f, %f, %f)\n", axes.z.x, axes.z.y, axes.z.z);
83        printf("# box.x=[%f, %f]\n", lowerBoundary.x, upperBoundary.x);
84        printf("# box.y=[%f, %f]\n", lowerBoundary.y, upperBoundary.y);
85        printf("# box.z=[%f, %f]\n", lowerBoundary.z, upperBoundary.z);
86}
87
88int main(int argc, char *argv[])
89{
90        return GeometryTestUtils::execute(
91                "Calculates approximate values of surface area, volume, sizes and axes of model. Adds to "
92                "model markers of bounding box apices and axes.", argc, argv, test);
93}
Note: See TracBrowser for help on using the repository browser.