42 std::vector<memoryx::EnvironmentalPrimitiveBasePtr> allPrimitives,
43 std::vector<memoryx::EnvironmentalPrimitiveBasePtr>& visibilePrimitives,
44 std::vector<memoryx::EnvironmentalPrimitiveBasePtr>& otherPrimitives)
46 for (memoryx::EnvironmentalPrimitiveBasePtr& p : allPrimitives)
54 Eigen::Matrix4f pose = FramedPosePtr::dynamicCast(p->getPose())->toEigen();
56 Eigen::Vector3f OBBDimensions = Vector3Ptr::dynamicCast(p->getOBBDimensions())->toEigen();
60 visibilePrimitives.push_back(p);
64 otherPrimitives.push_back(p);
73 Eigen::Vector3f nearTopRight = frustum.col(0);
74 Eigen::Vector3f nearTopLeft = frustum.col(1);
75 Eigen::Vector3f farTopLeft = frustum.col(2);
76 Eigen::Vector3f nearBottomLeft = frustum.col(3);
77 Eigen::Vector3f nearBottomRight = frustum.col(4);
78 Eigen::Vector3f farBottomRight = frustum.col(5);
79 Eigen::Vector3f farTopRight = frustum.col(15);
80 Eigen::Vector3f farBottomLeft = frustum.col(17);
82 Vector3BasePtr start =
new Vector3(nearTopLeft);
83 Vector3BasePtr stop =
new Vector3(nearBottomLeft);
85 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumNearLeft", start, stop, 1.0, color);
87 start =
new Vector3(farTopLeft);
88 stop =
new Vector3(farBottomLeft);
89 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumFarLeft", start, stop, 1.0, color);
91 start =
new Vector3(nearTopRight);
92 stop =
new Vector3(nearBottomRight);
93 debugDrawerTopicPrx->setLineVisu(
94 "primitiveMapper",
"frustumNearRight", start, stop, 1.0, color);
96 start =
new Vector3(farTopRight);
97 stop =
new Vector3(farBottomRight);
98 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumFarRight", start, stop, 1.0, color);
100 start =
new Vector3(nearBottomLeft);
101 stop =
new Vector3(nearBottomRight);
102 debugDrawerTopicPrx->setLineVisu(
103 "primitiveMapper",
"frustumNearBottom", start, stop, 1.0, color);
105 start =
new Vector3(farBottomLeft);
106 stop =
new Vector3(farBottomRight);
107 debugDrawerTopicPrx->setLineVisu(
108 "primitiveMapper",
"frustumFarBottom", start, stop, 1.0, color);
110 start =
new Vector3(nearBottomRight);
111 stop =
new Vector3(farBottomRight);
112 debugDrawerTopicPrx->setLineVisu(
113 "primitiveMapper",
"frustumRightBottom", start, stop, 1.0, color);
115 start =
new Vector3(nearBottomLeft);
116 stop =
new Vector3(farBottomLeft);
117 debugDrawerTopicPrx->setLineVisu(
118 "primitiveMapper",
"frustumLeftBottom", start, stop, 1.0, color);
120 start =
new Vector3(nearTopRight);
121 stop =
new Vector3(farTopRight);
122 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumRightTop", start, stop, 1.0, color);
124 start =
new Vector3(nearTopLeft);
125 stop =
new Vector3(farTopLeft);
126 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumLeftTop", start, stop, 1.0, color);
136 float imageSizeRatio = 640.0 / 480.0;
138 float farClipDistance = 3000.0;
139 float nearClipDistance = 400.0;
141 Eigen::Vector3f farCenter(0, 0, farClipDistance);
142 Eigen::Vector3f nearCenter(0, 0, nearClipDistance);
144 float a = -1.0 * std::tan(0.3926990925);
146 Eigen::Vector3f farVertical(0,
a * farClipDistance, 0);
147 Eigen::Vector3f farHorizontal(
a * farClipDistance * imageSizeRatio, 0, 0);
149 Eigen::Vector3f farTopLeft = farCenter - farVertical - farHorizontal;
150 Eigen::Vector3f farTopRight = farCenter - farVertical + farHorizontal;
152 Eigen::Vector3f farBottomLeft = farCenter + farVertical - farHorizontal;
153 Eigen::Vector3f farBottomRight = farCenter + farVertical + farHorizontal;
155 Eigen::Vector3f nearVertical(0,
a * nearClipDistance, 0);
156 Eigen::Vector3f nearHorizontal(
a * nearClipDistance * imageSizeRatio, 0, 0);
158 Eigen::Vector3f nearTopLeft = nearCenter - nearVertical - nearHorizontal;
159 Eigen::Vector3f nearTopRight = nearCenter - nearVertical + nearHorizontal;
161 Eigen::Vector3f nearBottomLeft = nearCenter + nearVertical - nearHorizontal;
162 Eigen::Vector3f nearBottomRight = nearCenter + nearVertical + nearHorizontal;
165 frustum.col(0) = nearTopRight;
166 frustum.col(1) = nearTopLeft;
167 frustum.col(2) = farTopLeft;
169 frustum.col(3) = nearBottomLeft;
170 frustum.col(4) = nearBottomRight;
171 frustum.col(5) = farBottomRight;
173 frustum.col(6) = nearTopLeft;
174 frustum.col(7) = nearBottomLeft;
175 frustum.col(8) = farBottomLeft;
177 frustum.col(9) = nearBottomRight;
178 frustum.col(10) = nearTopRight;
179 frustum.col(11) = farBottomRight;
181 frustum.col(12) = nearTopLeft;
182 frustum.col(13) = nearTopRight;
183 frustum.col(14) = nearBottomRight;
185 frustum.col(15) = farTopRight;
186 frustum.col(16) = farTopLeft;
187 frustum.col(17) = farBottomLeft;
191 transform *= Eigen::AngleAxisf(1.0 *
M_PI, Eigen::Vector3f::UnitZ());
194 for (
int i = 0; i < 18; i++)
196 Eigen::Vector4f temp = Eigen::Vector4f::Zero();
198 temp.head<3>() = frustum.col(i);
201 cameraToWorld.block<3, 3>(0, 0) *
transform.matrix().block<3, 3>(0, 0) * frustum.col(i);
202 frustum.col(i) += cameraToWorld.col(3).head<3>();
211 Eigen::Vector3f
a = pose.block<3, 3>(0, 0) * extent;
213 Eigen::Matrix3Xf points(3, 8);
214 points.col(0) = Eigen::Vector3f(
a(0),
a(1),
a(2));
215 points.col(1) = Eigen::Vector3f(
a(0),
a(1), -
a(2));
216 points.col(2) = Eigen::Vector3f(
a(0), -
a(1),
a(2));
217 points.col(3) = Eigen::Vector3f(
a(0), -
a(1), -
a(2));
218 points.col(4) = Eigen::Vector3f(-
a(0),
a(1),
a(2));
219 points.col(5) = Eigen::Vector3f(-
a(0),
a(1), -
a(2));
220 points.col(6) = Eigen::Vector3f(-
a(0), -
a(1),
a(2));
221 points.col(7) = Eigen::Vector3f(-
a(0), -
a(1), -
a(2));
223 for (
int i = 0; i < 8; i++)
225 Eigen::Vector3f point = pose.col(3).head<3>() + points.col(i);
238 for (
int i = 0; i < 18; i += 3)
240 Eigen::Vector3f u = frustum.col(i) - frustum.col(i + 1);
241 Eigen::Vector3f
v = frustum.col(i) - frustum.col(i + 2);
242 Eigen::Vector3f normal = u.cross(
v);
243 float dist = -1 * frustum.col(i).dot(normal);
244 if (normal.dot(point) + dist < 0)