42 void PrimitiveFilter::getPrimitivesInFieldOfView(std::vector<memoryx::EnvironmentalPrimitiveBasePtr> allPrimitives, std::vector<memoryx::EnvironmentalPrimitiveBasePtr>& visibilePrimitives, std::vector<memoryx::EnvironmentalPrimitiveBasePtr>& otherPrimitives)
44 for (memoryx::EnvironmentalPrimitiveBasePtr& p : allPrimitives)
52 Eigen::Matrix4f pose = FramedPosePtr::dynamicCast(p->getPose())->toEigen();
54 Eigen::Vector3f OBBDimensions = Vector3Ptr::dynamicCast(p->getOBBDimensions())->toEigen();
58 visibilePrimitives.push_back(p);
62 otherPrimitives.push_back(p);
70 Eigen::Vector3f nearTopRight = frustum.col(0);
71 Eigen::Vector3f nearTopLeft = frustum.col(1);
72 Eigen::Vector3f farTopLeft = frustum.col(2);
73 Eigen::Vector3f nearBottomLeft = frustum.col(3);
74 Eigen::Vector3f nearBottomRight = frustum.col(4);
75 Eigen::Vector3f farBottomRight = frustum.col(5);
76 Eigen::Vector3f farTopRight = frustum.col(15);
77 Eigen::Vector3f farBottomLeft = frustum.col(17);
79 Vector3BasePtr start =
new Vector3(nearTopLeft);
80 Vector3BasePtr stop =
new Vector3(nearBottomLeft);
82 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumNearLeft", start, stop, 1.0, color);
84 start =
new Vector3(farTopLeft);
85 stop =
new Vector3(farBottomLeft);
86 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumFarLeft", start, stop, 1.0, color);
88 start =
new Vector3(nearTopRight);
89 stop =
new Vector3(nearBottomRight);
90 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumNearRight", start, stop, 1.0, color);
92 start =
new Vector3(farTopRight);
93 stop =
new Vector3(farBottomRight);
94 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumFarRight", start, stop, 1.0, color);
96 start =
new Vector3(nearBottomLeft);
97 stop =
new Vector3(nearBottomRight);
98 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumNearBottom", start, stop, 1.0, color);
100 start =
new Vector3(farBottomLeft);
101 stop =
new Vector3(farBottomRight);
102 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumFarBottom", start, stop, 1.0, color);
104 start =
new Vector3(nearBottomRight);
105 stop =
new Vector3(farBottomRight);
106 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumRightBottom", start, stop, 1.0, color);
108 start =
new Vector3(nearBottomLeft);
109 stop =
new Vector3(farBottomLeft);
110 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumLeftBottom", start, stop, 1.0, color);
112 start =
new Vector3(nearTopRight);
113 stop =
new Vector3(farTopRight);
114 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumRightTop", start, stop, 1.0, color);
116 start =
new Vector3(nearTopLeft);
117 stop =
new Vector3(farTopLeft);
118 debugDrawerTopicPrx->setLineVisu(
"primitiveMapper",
"frustumLeftTop", start, stop, 1.0, color);
129 float imageSizeRatio = 640.0 / 480.0;
131 float farClipDistance = 3000.0;
132 float nearClipDistance = 400.0;
134 Eigen::Vector3f farCenter(0, 0, farClipDistance);
135 Eigen::Vector3f nearCenter(0, 0, nearClipDistance);
137 float a = -1.0 * std::tan(0.3926990925);
139 Eigen::Vector3f farVertical(0,
a * farClipDistance, 0);
140 Eigen::Vector3f farHorizontal(
a * farClipDistance * imageSizeRatio, 0, 0);
142 Eigen::Vector3f farTopLeft = farCenter - farVertical - farHorizontal;
143 Eigen::Vector3f farTopRight = farCenter - farVertical + farHorizontal;
145 Eigen::Vector3f farBottomLeft = farCenter + farVertical - farHorizontal;
146 Eigen::Vector3f farBottomRight = farCenter + farVertical + farHorizontal;
148 Eigen::Vector3f nearVertical(0,
a * nearClipDistance, 0);
149 Eigen::Vector3f nearHorizontal(
a * nearClipDistance * imageSizeRatio, 0, 0);
151 Eigen::Vector3f nearTopLeft = nearCenter - nearVertical - nearHorizontal;
152 Eigen::Vector3f nearTopRight = nearCenter - nearVertical + nearHorizontal;
154 Eigen::Vector3f nearBottomLeft = nearCenter + nearVertical - nearHorizontal;
155 Eigen::Vector3f nearBottomRight = nearCenter + nearVertical + nearHorizontal;
158 frustum.col(0) = nearTopRight;
159 frustum.col(1) = nearTopLeft;
160 frustum.col(2) = farTopLeft;
162 frustum.col(3) = nearBottomLeft;
163 frustum.col(4) = nearBottomRight;
164 frustum.col(5) = farBottomRight;
166 frustum.col(6) = nearTopLeft;
167 frustum.col(7) = nearBottomLeft;
168 frustum.col(8) = farBottomLeft;
170 frustum.col(9) = nearBottomRight;
171 frustum.col(10) = nearTopRight;
172 frustum.col(11) = farBottomRight;
174 frustum.col(12) = nearTopLeft;
175 frustum.col(13) = nearTopRight;
176 frustum.col(14) = nearBottomRight;
178 frustum.col(15) = farTopRight;
179 frustum.col(16) = farTopLeft;
180 frustum.col(17) = farBottomLeft;
184 transform *= Eigen::AngleAxisf(1.0 *
M_PI, Eigen::Vector3f::UnitZ());
187 for (
int i = 0; i < 18; i++)
189 Eigen::Vector4f temp = Eigen::Vector4f::Zero();
191 temp.head<3>() = frustum.col(i);
193 frustum.col(i) = cameraToWorld.block<3, 3>(0, 0) *
transform.matrix().block<3, 3>(0, 0) * frustum.col(i);
194 frustum.col(i) += cameraToWorld.col(3).head<3>();
202 Eigen::Vector3f
a = pose.block<3, 3>(0, 0) * extent;
204 Eigen::Matrix3Xf points(3, 8);
205 points.col(0) = Eigen::Vector3f(
a(0),
a(1),
a(2));
206 points.col(1) = Eigen::Vector3f(
a(0),
a(1), -
a(2));
207 points.col(2) = Eigen::Vector3f(
a(0), -
a(1),
a(2));
208 points.col(3) = Eigen::Vector3f(
a(0), -
a(1), -
a(2));
209 points.col(4) = Eigen::Vector3f(-
a(0),
a(1),
a(2));
210 points.col(5) = Eigen::Vector3f(-
a(0),
a(1), -
a(2));
211 points.col(6) = Eigen::Vector3f(-
a(0), -
a(1),
a(2));
212 points.col(7) = Eigen::Vector3f(-
a(0), -
a(1), -
a(2));
214 for (
int i = 0; i < 8; i ++)
216 Eigen::Vector3f point = pose.col(3).head<3>() + points.col(i);
229 for (
int i = 0; i < 18; i += 3)
231 Eigen::Vector3f u = frustum.col(i) - frustum.col(i + 1);
232 Eigen::Vector3f
v = frustum.col(i) - frustum.col(i + 2);
233 Eigen::Vector3f normal = u.cross(
v);
234 float dist = -1 * frustum.col(i).dot(normal);
235 if (normal.dot(point) + dist < 0)