MCPcopy Create free account
hub / github.com/PDAL/PDAL / setAutoXForm

Method setAutoXForm

pdal/Scaling.cpp:54–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53
54void Scaling::setAutoXForm(const PointViewSet& pvSet)
55{
56 bool xmod = m_xXform.m_offset.m_auto || m_xXform.m_scale.m_auto;
57 bool ymod = m_yXform.m_offset.m_auto || m_yXform.m_scale.m_auto;
58 bool zmod = m_zXform.m_offset.m_auto || m_zXform.m_scale.m_auto;
59 if (!xmod && !ymod && !zmod)
60 return;
61
62 double xmin = (std::numeric_limits<double>::max)();
63 double xmax = (std::numeric_limits<double>::lowest)();
64 double ymin = (std::numeric_limits<double>::max)();
65 double ymax = (std::numeric_limits<double>::lowest)();
66 double zmin = (std::numeric_limits<double>::max)();
67 double zmax = (std::numeric_limits<double>::lowest)();
68
69 for (const PointViewPtr& view : pvSet)
70 {
71 if (xmod)
72 for (PointId idx = 0; idx < view->size(); idx++)
73 {
74 double x = view->getFieldAs<double>(Dimension::Id::X, idx);
75 xmin = (std::min)(x, xmin);
76 xmax = (std::max)(x, xmax);
77 }
78 if (ymod)
79 for (PointId idx = 0; idx < view->size(); idx++)
80 {
81 double y = view->getFieldAs<double>(Dimension::Id::Y, idx);
82 ymin = (std::min)(y, ymin);
83 ymax = (std::max)(y, ymax);
84 }
85 if (zmod)
86 for (PointId idx = 0; idx < view->size(); idx++)
87 {
88 double z = view->getFieldAs<double>(Dimension::Id::Z, idx);
89 zmin = (std::min)(z, zmin);
90 zmax = (std::max)(z, zmax);
91 }
92 }
93
94 if (m_xXform.m_offset.m_auto)
95 m_xXform.m_offset.m_val = 0.5 * xmin + 0.5 * xmax;
96 if (m_yXform.m_offset.m_auto)
97 m_yXform.m_offset.m_val = 0.5 * ymin + 0.5 * ymax;
98 if (m_zXform.m_offset.m_auto)
99 m_zXform.m_offset.m_val = 0.5 * zmin + 0.5 * zmax;
100
101 if (m_xXform.m_scale.m_auto)
102 {
103 xmax = (std::max)(std::abs(xmax - m_xXform.m_offset.m_val),
104 std::abs(xmin - m_xXform.m_offset.m_val));
105 m_xXform.m_scale.m_val
106 = xmax ? xmax / (std::numeric_limits<int>::max)() : 1.;
107 }
108 if (m_yXform.m_scale.m_auto)
109 {
110 ymax = (std::max)(std::abs(ymax - m_yXform.m_offset.m_val),
111 std::abs(ymin - m_yXform.m_offset.m_val));

Callers 2

prerunFileMethod · 0.45
prerunFileMethod · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected