source: cpp/frams/_demos/geometry/surface_test.cpp @ 1302

Last change on this file since 1302 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: 2.0 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/meshbuilder.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        // Creating and preparing result Model object.
15        Model resultModel;
16        resultModel.open();
17        GeometryUtils::addAnchorToModel(resultModel);
18       
19        // Creating instance of Iterator class (MeshBuilder::ModelSurface in this case). Object is
20        // placed in stack memory, thus there is no heap memory allocation and creation is fast.
21        MeshBuilder::ModelSurface iterator(density);
22       
23        // Once created, iterator can be used many times, but must be initialized before every time.
24        iterator.initialize(&model);
25       
26        // Creating iterator output object in stack memory.
27        Pt3D point;
28       
29        // Method tryGetNext checks if next point exists and optionally updates fields of Pt3D object.
30        while (iterator.tryGetNext(point))
31        {
32                // Processing points created by iterator. In this case, they are added to result model as
33                // small spheres.
34                GeometryUtils::addPointToModel(point, resultModel);
35        }
36       
37        // After Iterator initialization there are two alternative ways of using it.
38        //
39        // First adds all points to the specified list:
40        // SListTempl<Pt3D> list;
41        // iterator.addAllPointsToList(list);
42        //
43        // Second executes specified operation for each point:
44        // Operation func;
45        // iterator.forEach(func);
46        // In this case, Operation is derived class of MeshBuilder::Callback class.
47       
48        // Finishing result Model and printing its genotype.
49        resultModel.close();
50        puts(resultModel.getF0Geno().getGenesAndFormat().c_str());
51}
52
53int main(int argc, char *argv[])
54{
55        return GeometryTestUtils::execute(
56                "Creates new model built of small spheres covering surface of input model and prints its "
57                "genotype.", argc, argv, test);
58}
Note: See TracBrowser for help on using the repository browser.