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

Last change on this file since 438 was 348, checked in by Maciej Komosinski, 10 years ago
  • explicit c_str() in SString instead of (const char*) cast
  • genetic converters and GenMan? are now thread-local which enables multi-threaded simulator separation
  • Property svn:eol-style set to native
File size: 1.9 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
[191]4
5#include "geometrytestutils.h"
6#include <frams/model/geometry/meshbuilder.h>
7#include <frams/model/model.h>
8#include <frams/util/3d.h>
9#include <stdio.h>
10
11void test(Model &model, const double density)
12{
13        // Creating and preparing result Model object.
14        Model resultModel;
15        resultModel.open();
16        GeometryTestUtils::addAnchorToModel(resultModel);
17       
18        // Creating instance of Iterator class (MeshBuilder::ModelSurface in this case). Object is
19        // placed in stack memory, thus there is no heap memory allocation and creation is fast.
20        MeshBuilder::ModelSurface iterator(density);
21       
22        // Once created, iterator can be used many times, but must be initialized before every time.
23        iterator.initialize(&model);
24       
25        // Creating iterator output object in stack memory.
26        Pt3D point;
27       
28        // Method tryGetNext checks if next point exists and optionally updates fields of Pt3D object.
29        while (iterator.tryGetNext(point))
30        {
31                // Processing points created by iterator. In this case, they are added to result model as
32                // small spheres.
33                GeometryTestUtils::addPointToModel(point, resultModel);
34        }
35       
36        // After Iterator initialization there are two alternative ways of using it.
37        //
38        // First adds all points to the specified list:
39        // SListTempl<Pt3D> list;
40        // iterator.addAllPointsToList(list);
41        //
42        // Second executes specified operation for each point:
43        // Operation func;
44        // iterator.forEach(func);
45        // In this case, Operation is derived class of MeshBuilder::Callback class.
46       
47        // Finishing result Model and printing its genotype.
48        resultModel.close();
[348]49        puts(resultModel.getF0Geno().toString().c_str());
[191]50}
51
52int main(int argc, char *argv[])
53{
54        return GeometryTestUtils::execute(
55                "Creates new model built of small spheres covering surface of input model and prints its "
56                "genotype.", argc, argv, test);
57}
Note: See TracBrowser for help on using the repository browser.