-
Notifications
You must be signed in to change notification settings - Fork 0
/
Integrator.cpp
83 lines (68 loc) · 2.26 KB
/
Integrator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <fantom/algorithm.hpp>
#include <fantom/register.hpp>
#include <fantom/graphics.hpp>
#include <fantom/fields.hpp>
#include <fantom/datastructures/LineSet.hpp>
using namespace fantom;
namespace {
class Integrator : public DataAlgorithm {
protected:
std::shared_ptr< const TensorFieldInterpolated< 3, Vector3 > > m_field;
std::shared_ptr< const Grid< 3 > > m_grid;
std::shared_ptr< const LineSet > m_seedLine;
size_t m_numPoints;
std::vector< std::vector< Point3 > > m_vertices;
float m_stepSize;
public:
struct Options : public VisAlgorithm::Options {
Options( fantom::Options::Control& control ) :
VisAlgorithm::Options( control )
{
add< TensorFieldInterpolated< 3, Vector3 > >( "Field", "3D vector field" );
add< LineSet >( "Seed line", "Starting points" );
add< float >( "Step size", "Integration step size", 0.1 );
}
};
struct DataOutputs : public DataAlgorithm::DataOutputs {
DataOutputs( fantom::DataOutputs::Control& control ) :
DataAlgorithm::DataOutputs( control )
{
add< LineSet >( "Streamlines" );
}
};
Integrator( InitData& data ) :
DataAlgorithm( data )
{
}
virtual void execute( const Algorithm::Options& options, const volatile bool& abortFlag ) override {
m_field = options.get< TensorFieldInterpolated< 3, Vector3 > >( "Field" );
m_grid = std::dynamic_pointer_cast< const Grid< 3 > >( m_field->domain() );
m_seedLine = options.get< const LineSet >( "Seed line" );
if( !m_seedLine ) {
infoLog() << "No input seedline!" << std::endl;
return;
}
if( !m_field ) {
infoLog() << "No input field!" << std::endl;
return;
}
for( int i=0; i<m_vertices.size(); i++ ) {
m_vertices[i].clear();
}
m_vertices.clear();
m_stepSize = options.get< float >( "Step size" );
}
void makeLineSet( const Algorithm::Options& options ) {
std::shared_ptr< LineSet > streamlines( new LineSet );
for( int i=0; i<m_vertices.size(); i++ ) {
std::vector< size_t > indices;
for( int j=0; j<m_vertices[i].size(); j++ ) {
indices.push_back( streamlines->addPoint( m_vertices[i][j] ) );
}
streamlines->addLine( indices );
}
setResult( "Streamlines", streamlines );
}
};
//AlgorithmRegister< Integrator > reg( "Integrator", "Line Integrator" );
}