gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
LongitudeLatitude.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 <algorithm>
7 #include "LongitudeLatitude.h"
8 #include "OpenFile.h"
9 
11  {GMSH_FULLRC, "View", nullptr, -1.}};
12 
13 extern "C" {
15 {
16  return new GMSH_LongituteLatitudePlugin();
17 }
18 }
19 
21 {
22  return "Plugin(LongituteLatitude) projects the view `View' "
23  "in longitude-latitude.\n\n"
24  "If `View' < 0, the plugin is run on the current view.\n\n"
25  "Plugin(LongituteLatitude) is executed in place.";
26 }
27 
29 {
30  return sizeof(LongituteLatitudeOptions_Number) / sizeof(StringXNumber);
31 }
32 
34 {
35  return &LongituteLatitudeOptions_Number[iopt];
36 }
37 
39 {
40  int iView = (int)LongituteLatitudeOptions_Number[0].def;
41 
42  PView *v1 = getView(iView, v);
43  if(!v1) return v;
44  PViewData *data1 = v1->getData();
45 
46  if(data1->isNodeData()) {
47  // tag all the nodes with "0" (the default tag)
48  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
49  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
50  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
51  if(data1->skipElement(step, ent, ele)) continue;
52  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
53  data1->tagNode(step, ent, ele, nod, 0);
54  }
55  }
56  }
57  }
58  double gxmin = 180, gxmax = -180, gymin = 90, gymax = -90;
59  // transform all "0" nodes
60  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
61  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
62  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
63  if(data1->skipElement(step, ent, ele)) continue;
64  int nbComp = data1->getNumComponents(step, ent, ele);
65  double vin[3], vout[3];
66  double xmin = M_PI, xmax = -M_PI;
67  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) {
68  double x, y, z;
69  int tag = data1->getNode(step, ent, ele, nod, x, y, z);
70  if(data1->isNodeData() && tag) continue;
71  double x2, y2, z2;
72  z2 = sqrt(x * x + y * y + z * z);
73  y2 = asin(z / z2);
74  x2 = atan2(y, x);
75  xmin = std::min(x2, xmin);
76  xmax = std::max(x2, xmax);
77  gxmin = std::min(x2 * 180 / M_PI, gxmin);
78  gxmax = std::max(x2 * 180 / M_PI, gxmax);
79  gymin = std::min(y2 * 180 / M_PI, gymin);
80  gymax = std::max(y2 * 180 / M_PI, gymax);
81  data1->setNode(step, ent, ele, nod, x2 * 180 / M_PI, y2 * 180 / M_PI,
82  0);
83  if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
84  if(nbComp == 3) {
85  for(int i = 0; i < 3; i++)
86  data1->getValue(step, ent, ele, nod, i, vin[i]);
87  vout[0] = -sin(x2) * vin[0] + cos(x2) * vin[1];
88  vout[1] = -sin(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) +
89  cos(y2) * vin[2];
90  vout[2] = cos(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) +
91  sin(y2) * vin[2];
92  for(int i = 0; i < 3; i++)
93  data1->setValue(step, ent, ele, nod, i, vout[i]);
94  }
95  }
96  if(xmax - xmin >
97  M_PI) { // periodicity check (broken for continuous views)
98  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) {
99  double x, y, z;
100  data1->getNode(step, ent, ele, nod, x, y, z);
101  if(xmax * 180 / M_PI - x > 180) x += 360;
102  data1->setNode(step, ent, ele, nod, x, y, z);
103  }
104  }
105  }
106  }
107  }
108  data1->destroyAdaptiveData();
109  data1->finalize();
110  SetBoundingBox();
111  SBoundingBox3d bb(gxmin, gymin, 0, gxmax, gymax, 0);
112  data1->setBoundingBox(bb);
113  v1->setChanged(true);
114  return v1;
115 }
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
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
PViewData::setValue
virtual void setValue(int step, int ent, int ele, int nod, int comp, double val)
Definition: PViewData.cpp:130
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
GMSH_LongituteLatitudePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: LongitudeLatitude.cpp:33
GMSH_LongituteLatitudePlugin::getNbOptions
int getNbOptions() const
Definition: LongitudeLatitude.cpp:28
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
LongitudeLatitude.h
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
SetBoundingBox
void SetBoundingBox(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
Definition: OpenFile.cpp:115
PView::setChanged
void setChanged(bool val)
Definition: PView.cpp:241
PViewData::tagNode
virtual void tagNode(int step, int ent, int ele, int nod, int tag)
Definition: PViewData.h:148
LongituteLatitudeOptions_Number
StringXNumber LongituteLatitudeOptions_Number[]
Definition: LongitudeLatitude.cpp:10
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
PViewData::destroyAdaptiveData
void destroyAdaptiveData()
Definition: PViewData.cpp:79
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
GMSH_LongituteLatitudePlugin
Definition: LongitudeLatitude.h:15
GMSH_LongituteLatitudePlugin::getHelp
std::string getHelp() const
Definition: LongitudeLatitude.cpp:20
GMSH_RegisterLongituteLatitudePlugin
GMSH_Plugin * GMSH_RegisterLongituteLatitudePlugin()
Definition: LongitudeLatitude.cpp:14
PViewData
Definition: PViewData.h:29
PViewData::getNumComponents
virtual int getNumComponents(int step, int ent, int ele)
Definition: PViewData.h:152
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
PViewData::setBoundingBox
virtual void setBoundingBox(SBoundingBox3d &box)=0
SBoundingBox3d
Definition: SBoundingBox3d.h:21
PViewData::finalize
virtual bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewData.cpp:30
OpenFile.h
GMSH_LongituteLatitudePlugin::execute
PView * execute(PView *)
Definition: LongitudeLatitude.cpp:38