14 #ifndef CORE_VISUALIZATION_ROOT_ADAPTOR_H_
15 #define CORE_VISUALIZATION_ROOT_ADAPTOR_H_
20 #include <TGeoManager.h>
24 #include "Math/AxisAngle.h"
25 #include "Math/EulerAngles.h"
37 using ROOT::Math::AxisAngle;
38 using ROOT::Math::EulerAngles;
55 if (total_steps % param->visualization_interval != 0) {
64 auto container =
new TGeoVolumeAssembly(
"A");
66 top_->AddNode(container,
top_->GetNdaughters());
69 gSystem->ProcessEvents();
70 gGeoManager->Export(
outfile_.c_str(),
"biodynamo");
73 void DrawInCanvas(
size_t w = 300,
size_t h = 300, std::string opt =
"") {
74 canvas_->GetListOfPrimitives()->Clear();
76 canvas_->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume(),
"all");
79 canvas_->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume(),
82 canvas_->SetCanvasSize(
static_cast<UInt_t
>(w),
static_cast<UInt_t
>(h));
89 gGeoManager =
new TGeoManager(
"Visualization",
"BioDynaMo");
90 canvas_ =
new TCanvas(
"BioDynaMo Canvas",
"For ROOT Notebooks ", 300, 300);
96 gGeoManager->SetNsegments(15);
99 mat_solid_ =
new TGeoMaterial(
"Solid", .938, 1., 10000.);
105 top_ =
new TGeoVolumeAssembly(
"WORLD");
107 gGeoManager->SetTopVolume(
top_);
108 gGeoManager->SetVisLevel(4);
117 canvas_->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume(),
"all");
133 "Tried to add a shape to the Root visualization that's not "
134 "one of the supported types : ",
145 auto x = massLocation[0];
146 auto y = massLocation[1];
147 auto z = massLocation[2];
148 auto position =
new TGeoTranslation(x, y, z);
149 auto volume = gGeoManager->MakeSphere(name.c_str(),
med_solid_, 0, radius);
150 volume->SetLineColor(kBlue);
151 container->AddNode(volume, container->GetNdaughters(), position);
158 auto radius = neurite->GetDiameter() / 2;
159 auto half_length = neurite->GetLength() / 2;
160 auto massLocation = neurite->GetPosition();
161 auto x = massLocation[0];
162 auto y = massLocation[1];
163 auto z = massLocation[2];
164 auto trans =
new TGeoTranslation(x, y, z);
167 TVector3 orig(0, 0, 1);
171 Real3 d = neurite->GetSpringAxis();
172 TVector3 dir(d[0], d[1], d[2]);
176 auto dot_product = dir.Dot(orig);
177 auto angle = std::acos(dot_product);
179 TVector3 n = dir.Cross(orig);
181 auto axis = AxisAngle::AxisVector(n[0], n[1], n[2]);
182 AxisAngle aa(axis, angle);
184 TGeoRotation *rot =
new TGeoRotation(
"rot",
Math::ToDegree(ea.Phi()),
187 TGeoCombiTrans *transrot =
new TGeoCombiTrans(*trans, *rot);
188 auto volume = gGeoManager->MakeTube(name.c_str(),
med_solid_, 0, radius,
190 volume->SetLineColor(kBlue);
191 container->AddNode(volume, container->GetNdaughters(), transrot);
193 Log::Error(
"RootAdaptor",
"This is not a cylindrical shaped object!");
Contains code required by all agents.
virtual Shape GetShape() const =0
virtual const char * GetTypeName() const
virtual const Real3 & GetPosition() const =0
virtual real_t GetDiameter() const =0
const AgentUid & GetUid() const
static void Error(const std::string &location, const Args &... parts)
Prints error message.
virtual void ForEachAgent(const std::function< void(Agent *)> &function, Functor< bool, Agent * > *filter=nullptr)
The class that bridges the simulation code with ROOT Visualization.
TGeoVolume * top_
Top volumes for TGeo and TEve (world)
TGeoMedium * med_empty_space_
void DrawInCanvas(size_t w=300, size_t h=300, std::string opt="")
TGeoMaterial * mat_empty_space_
Eve materials and medium.
int max_viz_nodes_
Max visualized shapes per volume.
void AddBranch(const Agent *agent, TGeoVolume *container)
Recursively adds sphere and its daughters to the container.
void AddSphere(const Agent *agent, TGeoVolume *container)
Adds a sphere object to the volume.
TGeoMaterial * mat_solid_
void Visualize(uint64_t total_steps)
Visualize one timestep.
void AddCylinder(const Agent *agent, TGeoVolume *container)
Adds a cylinder object to the volume.
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
const Param * GetParam() const
Returns the simulation parameters.
const std::string & GetUniqueName() const
Returns the name of the simulation.
static real_t ToDegree(real_t rad)