gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Transform.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include "Transform.h"
7 
9  {GMSH_FULLRC, "A11", nullptr, 1.},
10  {GMSH_FULLRC, "A12", nullptr, 0.},
11  {GMSH_FULLRC, "A13", nullptr, 0.},
12  {GMSH_FULLRC, "A21", nullptr, 0.},
13  {GMSH_FULLRC, "A22", nullptr, 1.},
14  {GMSH_FULLRC, "A23", nullptr, 0.},
15  {GMSH_FULLRC, "A31", nullptr, 0.},
16  {GMSH_FULLRC, "A32", nullptr, 0.},
17  {GMSH_FULLRC, "A33", nullptr, 1.},
18  {GMSH_FULLRC, "Tx", nullptr, 0.},
19  {GMSH_FULLRC, "Ty", nullptr, 0.}, // cannot use T2 (reserved token in parser)
20  {GMSH_FULLRC, "Tz", nullptr, 0.}, // cannot use T3 (reserved token in parser)
21  {GMSH_FULLRC, "SwapOrientation", nullptr, 0.},
22  {GMSH_FULLRC, "View", nullptr, -1.}};
23 
24 extern "C" {
26 {
27  return new GMSH_TransformPlugin();
28 }
29 }
30 
31 std::string GMSH_TransformPlugin::getHelp() const
32 {
33  return "Plugin(Transform) transforms the homogeneous "
34  "node coordinates (x,y,z,1) of the elements in "
35  "the view `View' by the matrix\n\n"
36  "[`A11' `A12' `A13' `Tx']\n"
37  "[`A21' `A22' `A23' `Ty']\n"
38  "[`A31' `A32' `A33' `Tz'].\n\n"
39  "If `SwapOrientation' is set, the orientation of the "
40  "elements is reversed.\n\n"
41  "If `View' < 0, the plugin is run on the current view.\n\n"
42  "Plugin(Transform) is executed in-place.";
43 }
44 
46 {
47  return sizeof(TransformOptions_Number) / sizeof(StringXNumber);
48 }
49 
51 {
52  return &TransformOptions_Number[iopt];
53 }
54 
56 {
57  double mat[3][4];
58 
59  mat[0][0] = TransformOptions_Number[0].def;
60  mat[0][1] = TransformOptions_Number[1].def;
61  mat[0][2] = TransformOptions_Number[2].def;
62  mat[1][0] = TransformOptions_Number[3].def;
63  mat[1][1] = TransformOptions_Number[4].def;
64  mat[1][2] = TransformOptions_Number[5].def;
65  mat[2][0] = TransformOptions_Number[6].def;
66  mat[2][1] = TransformOptions_Number[7].def;
67  mat[2][2] = TransformOptions_Number[8].def;
68 
69  mat[0][3] = TransformOptions_Number[9].def;
70  mat[1][3] = TransformOptions_Number[10].def;
71  mat[2][3] = TransformOptions_Number[11].def;
72 
73  int swap = (int)TransformOptions_Number[12].def;
74  int iView = (int)TransformOptions_Number[13].def;
75 
76  PView *v1 = getView(iView, v);
77  if(!v1) return v;
78 
79  PViewData *data1 = v1->getData();
80 
81  if(data1->isNodeData()) {
82  // tag all the nodes with "0" (the default tag)
83  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
84  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
85  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
86  if(data1->skipElement(step, ent, ele)) continue;
87  if(swap) data1->reverseElement(step, ent, ele);
88  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
89  data1->tagNode(step, ent, ele, nod, 0);
90  }
91  }
92  }
93  }
94 
95  // transform all "0" nodes
96  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
97  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
98  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
99  if(data1->skipElement(step, ent, ele)) continue;
100  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) {
101  double x, y, z;
102  int tag = data1->getNode(step, ent, ele, nod, x, y, z);
103  if(data1->isNodeData() && tag) continue;
104  double x2, y2, z2;
105  x2 = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
106  y2 = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
107  z2 = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
108  data1->setNode(step, ent, ele, nod, x2, y2, z2);
109  if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
110  }
111  }
112  }
113  }
114 
115  data1->finalize();
116 
117  v1->setChanged(true);
118  return v1;
119 }
PView
Definition: PView.h:27
PViewData::skipElement
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
Definition: PViewData.cpp:90
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
PViewData::isNodeData
virtual bool isNodeData()
Definition: PViewData.h:218
PViewData::getNode
virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z)
Definition: PViewData.h:141
StringXNumber
Definition: Options.h:918
PViewData::reverseElement
virtual void reverseElement(int step, int ent, int ele)
Definition: PViewData.h:200
PViewData::setNode
virtual void setNode(int step, int ent, int ele, int nod, double x, double y, double z)
Definition: PViewData.cpp:124
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
GMSH_TransformPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Transform.cpp:50
PView::setChanged
void setChanged(bool val)
Definition: PView.cpp:241
GMSH_TransformPlugin
Definition: Transform.h:15
GMSH_TransformPlugin::getNbOptions
int getNbOptions() const
Definition: Transform.cpp:45
PViewData::tagNode
virtual void tagNode(int step, int ent, int ele, int nod, int tag)
Definition: PViewData.h:148
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
swap
void swap(double &a, double &b)
Definition: meshTriangulation.cpp:27
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
GMSH_RegisterTransformPlugin
GMSH_Plugin * GMSH_RegisterTransformPlugin()
Definition: Transform.cpp:25
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
PViewData
Definition: PViewData.h:29
Transform.h
GMSH_TransformPlugin::execute
PView * execute(PView *)
Definition: Transform.cpp:55
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
GMSH_TransformPlugin::getHelp
std::string getHelp() const
Definition: Transform.cpp:31
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
TransformOptions_Number
StringXNumber TransformOptions_Number[]
Definition: Transform.cpp:8
PViewData::finalize
virtual bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewData.cpp:30