25 #include <vtkMatrix4x4.h>
28 #include "vnl/vnl_random.h"
29 #include "vnl/vnl_math.h"
32 : m_LastGenerationWasSuccess( false )
44 m_LastGenerationWasSuccess =
false;
46 network->SetGeometry( this->GenerateDefaultGeometry() );
48 switch (networkTypeId) {
50 GenerateSyntheticCubeNetwork( network, paramterOne, parameterTwo );
53 GenerateSyntheticCenterToSurfaceNetwork( network, paramterOne, parameterTwo );
56 GenerateSyntheticRandomNetwork( network, paramterOne, parameterTwo );
68 network->UpdateBounds();
87 geometry->SetOrigin(origin);
94 geometry->SetSpacing(spacing);
98 transformMatrix->SetElement(0,0,one);
99 transformMatrix->SetElement(1,0,zero);
100 transformMatrix->SetElement(2,0,zero);
101 transformMatrix->SetElement(0,1,zero);
102 transformMatrix->SetElement(1,1,one);
103 transformMatrix->SetElement(2,1,zero);
104 transformMatrix->SetElement(0,2,zero);
105 transformMatrix->SetElement(1,2,zero);
106 transformMatrix->SetElement(2,2,one);
108 transformMatrix->SetElement(0,3,origin[0]);
109 transformMatrix->SetElement(1,3,origin[1]);
110 transformMatrix->SetElement(2,3,origin[2]);
111 transformMatrix->SetElement(3,3,1);
112 geometry->SetIndexToWorldTransformByVtkMatrix( transformMatrix );
114 geometry->SetImageGeometry(
true);
123 std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap;
126 for(
int loopX( 0 ); loopX < cubeExtent; loopX++ )
128 for(
int loopY( 0 ); loopY < cubeExtent; loopY++ )
130 for(
int loopZ( 0 ); loopZ < cubeExtent; loopZ++ )
132 std::vector< float > position;
134 std::stringstream labelStream;
135 labelStream << vertexID;
136 label = labelStream.str();
138 position.push_back( loopX * distance );
139 position.push_back( loopY * distance );
140 position.push_back( loopZ * distance );
143 network->SetLabel( newVertex, label );
144 network->SetCoordinates( newVertex, position );
146 if ( idToVertexMap.count( vertexID ) > 0 )
148 MITK_ERROR <<
"Aborting network creation, duplicate vertex ID generated.";
149 m_LastGenerationWasSuccess =
false;
152 idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( vertexID, newVertex) );
159 int edgeID(0), edgeSourceID(0), edgeTargetID(0);
166 for(
int loopX( 0 ); loopX < cubeExtent; loopX++ )
168 for(
int loopY( 0 ); loopY < cubeExtent; loopY++ )
170 for(
int loopZ( 0 ); loopZ < cubeExtent; loopZ++ )
176 edgeTargetID = edgeSourceID - cubeExtent * cubeExtent;
178 source = idToVertexMap.find( edgeSourceID )->second;
179 target = idToVertexMap.find( edgeTargetID )->second;
180 network->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight);
186 edgeTargetID = edgeSourceID - cubeExtent;
188 source = idToVertexMap.find( edgeSourceID )->second;
189 target = idToVertexMap.find( edgeTargetID )->second;
190 network->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight);
196 edgeTargetID = edgeSourceID - 1;
198 source = idToVertexMap.find( edgeSourceID )->second;
199 target = idToVertexMap.find( edgeTargetID )->second;
200 network->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight);
209 m_LastGenerationWasSuccess =
true;
216 vnl_random rng( (
unsigned int) rand() );
221 std::vector< float > position;
223 std::stringstream labelStream;
224 labelStream << vertexID;
225 label = labelStream.str();
227 position.push_back( 0 );
228 position.push_back( 0 );
229 position.push_back( 0 );
231 centerVertex = network->AddVertex( vertexID );
232 network->SetLabel( centerVertex, label );
233 network->SetCoordinates( centerVertex, position );
240 for(
int loopID( 1 ); loopID < numberOfPoints; loopID++ )
243 std::vector< float > position;
245 std::stringstream labelStream;
246 labelStream << loopID;
247 label = labelStream.str();
250 const double uVariable = rng.drand64( 0.0 , 1.0);
251 const double vVariable = rng.drand64( 0.0 , 1.0);
252 const double phi = 2 * vnl_math::pi * uVariable;
253 const double theta = std::acos( 2 * vVariable - 1 );
255 double xpos = radius * std::cos( phi ) * std::sin( theta );
256 double ypos = radius * std::sin( phi ) * std::sin( theta );
257 double zpos = radius * std::cos( theta );
259 position.push_back( xpos );
260 position.push_back( ypos );
261 position.push_back( zpos );
264 network->SetLabel( newVertex, label );
265 network->SetCoordinates( newVertex, position );
267 network->AddEdge( newVertex, centerVertex, loopID, 0, edgeWeight);
269 m_LastGenerationWasSuccess =
true;
276 double radius = 5 * std::sqrt( (
float) numberOfPoints );
278 vnl_random rng( (
unsigned int) rand() );
281 std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap;
284 for(
int loopID( 0 ); loopID < numberOfPoints; loopID++ )
287 std::vector< float > position;
289 std::stringstream labelStream;
290 labelStream << loopID;
291 label = labelStream.str();
294 const double uVariable = rng.drand64( 0.0 , 1.0);
295 const double vVariable = rng.drand64( 0.0 , 1.0);
296 const double phi = 2 * vnl_math::pi * uVariable;
297 const double theta = std::acos( 2 * vVariable - 1 );
299 double xpos = radius * std::cos( phi ) * std::sin( theta );
300 double ypos = radius * std::sin( phi ) * std::sin( theta );
301 double zpos = radius * std::cos( theta );
303 position.push_back( xpos );
304 position.push_back( ypos );
305 position.push_back( zpos );
308 network->SetLabel( newVertex, label );
309 network->SetCoordinates( newVertex, position );
311 if ( idToVertexMap.count( loopID ) > 0 )
313 MITK_ERROR <<
"Aborting network creation, duplicate vertex ID generated.";
314 m_LastGenerationWasSuccess =
false;
317 idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( loopID, newVertex) );
327 for(
int loopID( 0 ); loopID < numberOfPoints; loopID++ )
331 for(
int innerLoopID( loopID ); innerLoopID < numberOfPoints; innerLoopID++ )
333 if( rng.drand64( 0.0 , 1.0) > threshold)
339 source = idToVertexMap.find( loopID )->second;
340 target = idToVertexMap.find( innerLoopID )->second;
341 network->AddEdge( source, target, loopID, innerLoopID, edgeWeight);
347 m_LastGenerationWasSuccess =
true;
352 return m_LastGenerationWasSuccess;
This file defines the data properties for connectomics networks in MITK.
mitk::ConnectomicsNetwork::Pointer CreateSyntheticNetwork(int networkTypeId, int paramterOne, double parameterTwo)
void GenerateSyntheticCubeNetwork(mitk::ConnectomicsNetwork::Pointer network, int cubeExtent, double distance)
void GenerateSyntheticRandomNetwork(mitk::ConnectomicsNetwork::Pointer network, int numberOfPoints, double threshold)
void GenerateSyntheticCenterToSurfaceNetwork(mitk::ConnectomicsNetwork::Pointer network, int numberOfPoints, double radius)
boost::graph_traits< NetworkType >::vertex_descriptor VertexDescriptorType
const std::string connectomicsDataAdditionalHeaderInformation
Additional header information.
ConnectomicsSyntheticNetworkGenerator()
bool WasGenerationSuccessfull()
mitk::Geometry3D::Pointer GenerateDefaultGeometry()
~ConnectomicsSyntheticNetworkGenerator()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.