38 #ifndef HPP_FCL_BV_SPLITTER_H
39 #define HPP_FCL_BV_SPLITTER_H
73 tri_indices = tri_indices_;
78 void computeRule(
const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
83 computeRule_mean(bv, primitive_indices, num_primitives);
86 computeRule_median(bv, primitive_indices, num_primitives);
89 computeRule_bvcenter(bv, primitive_indices, num_primitives);
92 std::cerr <<
"Split method not supported" << std::endl;
99 return q[split_axis] > split_value;
133 void computeRule_bvcenter(
const BV& bv,
unsigned int*,
int)
135 Vec3f center = bv.center();
138 if(bv.width() >= bv.height() && bv.width() >= bv.depth())
140 else if(bv.height() >= bv.width() && bv.height() >= bv.depth())
144 split_value = center[axis];
148 void computeRule_mean(
const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
152 if(bv.width() >= bv.height() && bv.width() >= bv.depth())
154 else if(bv.height() >= bv.width() && bv.height() >= bv.depth())
162 for(
int i = 0; i < num_primitives; ++i)
164 const Triangle& t = tri_indices[primitive_indices[i]];
165 sum += (vertices[t[0]][split_axis] + vertices[t[1]][split_axis] + vertices[t[2]][split_axis]);
172 for(
int i = 0; i < num_primitives; ++i)
174 sum += vertices[primitive_indices[i]][split_axis];
178 split_value = sum / num_primitives;
182 void computeRule_median(
const BV& bv,
unsigned int* primitive_indices,
int num_primitives)
186 if(bv.width() >= bv.height() && bv.width() >= bv.depth())
188 else if(bv.height() >= bv.width() && bv.height() >= bv.depth())
192 std::vector<FCL_REAL> proj(num_primitives);
196 for(
int i = 0; i < num_primitives; ++i)
198 const Triangle& t = tri_indices[primitive_indices[i]];
199 proj[i] = (vertices[t[0]][split_axis] + vertices[t[1]][split_axis] + vertices[t[2]][split_axis]) / 3;
204 for(
int i = 0; i < num_primitives; ++i)
205 proj[i] = vertices[primitive_indices[i]][split_axis];
208 std::sort(proj.begin(), proj.end());
210 if(num_primitives % 2 == 1)
212 split_value = proj[(num_primitives - 1) / 2];
216 split_value = (proj[num_primitives / 2] + proj[num_primitives / 2 - 1]) / 2;
235 void BVSplitter<OBB>::computeRule_bvcenter(
const OBB& bv,
unsigned int* primitive_indices,
int num_primitives);
238 void BVSplitter<OBB>::computeRule_mean(
const OBB& bv,
unsigned int* primitive_indices,
int num_primitives);
241 void BVSplitter<OBB>::computeRule_median(
const OBB& bv,
unsigned int* primitive_indices,
int num_primitives);
244 void BVSplitter<RSS>::computeRule_bvcenter(
const RSS& bv,
unsigned int* primitive_indices,
int num_primitives);
247 void BVSplitter<RSS>::computeRule_mean(
const RSS& bv,
unsigned int* primitive_indices,
int num_primitives);
250 void BVSplitter<RSS>::computeRule_median(
const RSS& bv,
unsigned int* primitive_indices,
int num_primitives);
253 void BVSplitter<kIOS>::computeRule_bvcenter(
const kIOS& bv,
unsigned int* primitive_indices,
int num_primitives);
256 void BVSplitter<kIOS>::computeRule_mean(
const kIOS& bv,
unsigned int* primitive_indices,
int num_primitives);
259 void BVSplitter<kIOS>::computeRule_median(
const kIOS& bv,
unsigned int* primitive_indices,
int num_primitives);
262 void BVSplitter<OBBRSS>::computeRule_bvcenter(
const OBBRSS& bv,
unsigned int* primitive_indices,
int num_primitives);
265 void BVSplitter<OBBRSS>::computeRule_mean(
const OBBRSS& bv,
unsigned int* primitive_indices,
int num_primitives);
268 void BVSplitter<OBBRSS>::computeRule_median(
const OBBRSS& bv,
unsigned int* primitive_indices,
int num_primitives);