Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ViewFEMesh.hh
Go to the documentation of this file.
1#ifndef G_VIEW_FE_MESH
2#define G_VIEW_FE_MESH
3
4#include <string>
5#ifndef __CINT__
6#include <map>
7#endif
8
9#include <TCanvas.h>
10#include <TMatrixD.h>
11#include <TArrayD.h>
12#include <TGaxis.h>
13#include <TPolyLine.h>
14#include <TPolyLine3D.h>
15#include <TString.h>
16#include <TH2D.h>
17
18#include "ViewDrift.hh"
19#include "ComponentFieldMap.hh"
20#include "ComponentCST.hh"
21
22namespace Garfield {
23
24/// Draw the mesh of a field-map component.
25
27
28 public:
29 /// Constructor
30 ViewFEMesh();
31 /// Destructor
33
34 TCanvas* GetCanvas();
35
36 /// Set the canvas to be painted on.
37 void SetCanvas(TCanvas* c);
38 /// Set the component from which to retrieve the mesh and field.
40
41 /// Set area to be plotted to the default.
42 void SetArea();
43 /// Set area to be plotted explicitly.
44 void SetArea(const double xmin, const double ymin, const double zmin,
45 const double xmax, const double ymax, const double zmax);
46
47 /// Reset the projection plane.
49 /// Set the projection plane.
50 void SetPlane(double fx, double fy, double fz, double x0, double y0,
51 double z0);
52
53 // Axes
54 void SetXaxis(TGaxis* ax);
55 void SetYaxis(TGaxis* ay);
56 void SetXaxisTitle(const char* xtitle);
57 void SetYaxisTitle(const char* ytitle);
58 void EnableAxes() { m_drawAxes = true; }
59 void DisableAxes() { m_drawAxes = false; }
60
61 /// Plot method to be called by user
62 bool Plot();
63
64 /// Element fill switch; 2D only, set false for wireframe mesh
65 void SetFillMesh(const bool f) { m_fillMesh = f; }
66
67 /// Associate a color with each element material map ID;
68 /// Uses ROOT color numberings
69 void SetColor(int matID, int colorID) { m_colorMap[matID] = colorID; }
70 void SetFillColor(int matID, int colorID) {
71 m_colorMap_fill[matID] = colorID;
72 }
73
74 /// Set the optional associated ViewDrift
75 void SetViewDrift(ViewDrift* vd) { m_viewDrift = vd; }
76
77 /// Show filled mesh elements
79 m_plotMeshBorders = true;
80 m_fillMesh = true;
81 }
82
83 /// Switch on/off debugging output.
84 void EnableDebugging(const bool on = true) { m_debug = on; }
85
86 /// Create a default set of custom-made axes.
87 void CreateDefaultAxes();
88
89 /// Disable a material so that its mesh cells are not drawn
90 void DisableMaterial(int materialID) {
91 m_disabledMaterial[materialID] = true;
92 }
93
94 private:
95 std::string m_className;
96 std::string m_label;
97
98 // Options
99 bool m_debug;
100 bool m_fillMesh;
101
102 // Canvas
103 TCanvas* m_canvas;
104 bool m_hasExternalCanvas;
105
106 // Viewing plane
107 double project[3][3];
108 double plane[4];
109
110 // Box dimensions
111 bool m_hasUserArea;
112 double m_xMin, m_yMin, m_zMin;
113 double m_xMax, m_yMax, m_zMax;
114
115 // The field map object
116 ComponentFieldMap* m_component;
117
118 // Optional associated ViewDrift object
119 ViewDrift* m_viewDrift;
120 bool m_plotMeshBorders;
121
122 // Axes
123 TGaxis* m_xaxis, *m_yaxis;
124 TH2D* m_axes;
125 bool m_drawAxes;
126
127 // The mesh, stored as a vector of TPolyLine(3D) objects
128 std::vector<TPolyLine*> m_mesh;
129 std::vector<TPolyLine*> m_driftLines;
130
131// The color map
132#ifndef __CINT__
133 std::map<int, int> m_colorMap;
134 std::map<int, int> m_colorMap_fill;
135
136 // Disabled materials -> not shown in the mesh view
137 std::map<int, bool> m_disabledMaterial;
138#endif
139 // Element plotting methods
140 void DrawElements();
141 void DrawCST(ComponentCST* componentCST);
142 bool InView(double x, double y);
143 bool LinesCrossed(double x1, double y1, double x2, double y2, double u1,
144 double v1, double u2, double v2, double& xc, double& yc);
145 bool OnLine(double x1, double y1, double x2, double y2, double u, double v);
146 void RemoveCrossings(std::vector<double>& x, std::vector<double>& y);
147 bool PlaneCut(double x1, double y1, double z1, double x2, double y2,
148 double z2, TMatrixD& xMat);
149 bool PlaneCoords(double x, double y, double z, const TMatrixD& projMat,
150 TMatrixD& xMat);
151 void ClipToView(std::vector<double>& px, std::vector<double>& py,
152 std::vector<double>& cx, std::vector<double>& cy);
153 bool IsInPolygon(double x, double y, std::vector<double>& px,
154 std::vector<double>& py, bool& edge);
155
156 // Plot method to be called by Plot() for CST cubic elements
157 // available are "xy", "yz" and "xz"
158};
159}
160#endif
Base class for components based on finite-element field maps.
Visualize drift lines and tracks.
Definition: ViewDrift.hh:15
Draw the mesh of a field-map component.
Definition: ViewFEMesh.hh:26
void SetXaxisTitle(const char *xtitle)
Definition: ViewFEMesh.cc:212
void CreateDefaultAxes()
Create a default set of custom-made axes.
Definition: ViewFEMesh.cc:222
void SetCanvas(TCanvas *c)
Set the canvas to be painted on.
Definition: ViewFEMesh.cc:61
ViewFEMesh()
Constructor.
Definition: ViewFEMesh.cc:13
void SetComponent(ComponentFieldMap *comp)
Set the component from which to retrieve the mesh and field.
Definition: ViewFEMesh.cc:50
void SetFillMeshWithBorders()
Show filled mesh elements.
Definition: ViewFEMesh.hh:78
void SetViewDrift(ViewDrift *vd)
Set the optional associated ViewDrift.
Definition: ViewFEMesh.hh:75
TCanvas * GetCanvas()
Definition: ViewFEMesh.cc:72
void SetFillColor(int matID, int colorID)
Definition: ViewFEMesh.hh:70
void DisableMaterial(int materialID)
Disable a material so that its mesh cells are not drawn.
Definition: ViewFEMesh.hh:90
void SetYaxisTitle(const char *ytitle)
Definition: ViewFEMesh.cc:217
bool Plot()
Plot method to be called by user.
Definition: ViewFEMesh.cc:97
void SetPlane(double fx, double fy, double fz, double x0, double y0, double z0)
Set the projection plane.
Definition: ViewFEMesh.cc:145
void SetArea()
Set area to be plotted to the default.
Definition: ViewFEMesh.cc:93
void EnableDebugging(const bool on=true)
Switch on/off debugging output.
Definition: ViewFEMesh.hh:84
void SetColor(int matID, int colorID)
Definition: ViewFEMesh.hh:69
~ViewFEMesh()
Destructor.
Definition: ViewFEMesh.cc:45
void SetXaxis(TGaxis *ax)
Definition: ViewFEMesh.cc:206
void SetYaxis(TGaxis *ay)
Definition: ViewFEMesh.cc:209
void SetFillMesh(const bool f)
Element fill switch; 2D only, set false for wireframe mesh.
Definition: ViewFEMesh.hh:65
void SetDefaultProjection()
Reset the projection plane.
Definition: ViewFEMesh.cc:185