std::pair<Real, Real> Tri3::min_and_max_angle() const { Point v10 ( this->point(1) - this->point(0) ); Point v20 ( this->point(2) - this->point(0) ); Point v21 ( this->point(2) - this->point(1) ); const Real len_10=v10.size(), len_20=v20.size(), len_21=v21.size() ; const Real theta0=std::acos(( v10*v20)/len_10/len_20), theta1=std::acos((-v10*v21)/len_10/len_21), theta2=libMesh::pi - theta0 - theta1 ; libmesh_assert_greater (theta0, 0.); libmesh_assert_greater (theta1, 0.); libmesh_assert_greater (theta2, 0.); return std::make_pair(std::min(theta0, std::min(theta1,theta2)), std::max(theta0, std::max(theta1,theta2))); }
void Planet::drawAtmoCell(float r1, float r2, float a1, float a2, Color4F r1col, Color4F r2col) { Vec2 v11(r1 * cosf(a1), r1 * sinf(a1)); Vec2 v12(r1 * cosf(a2), r1 * sinf(a2)); Vec2 v21(r2 * cosf(a1), r2 * sinf(a1)); Vec2 v22(r2 * cosf(a2), r2 * sinf(a2)); node()->drawTriangleGradient(v11, v21, v12, r1col, r2col, r1col); node()->drawTriangleGradient(v12, v21, v22, r1col, r2col, r2col); }
void Planet::drawStratumCell(float a1, float a2, const Stratum& s1, const Stratum& s2) { float r11 = _coreRadius + s1.alt1; float r12 = _coreRadius + s2.alt1; float r21 = _coreRadius + s1.alt2; float r22 = _coreRadius + s2.alt2; Vec2 v11(r11 * cosf(a1), r11 * sinf(a1)); Vec2 v12(r12 * cosf(a2), r12 * sinf(a2)); Vec2 v21(r21 * cosf(a1), r21 * sinf(a1)); Vec2 v22(r22 * cosf(a2), r22 * sinf(a2)); node()->drawTriangleGradient(v11, v21, v12, s1.col1, s2.col1, s1.col2); node()->drawTriangleGradient(v12, v21, v22, s1.col2, s2.col1, s2.col2); }
template <typename PointInT, typename PointOutT> void pcl::ESFEstimation<PointInT, PointOutT>::computeESF ( PointCloudIn &pc, std::vector<float> &hist) { const int binsize = 64; unsigned int sample_size = 20000; srand (static_cast<unsigned int> (time (0))); int maxindex = static_cast<int> (pc.points.size ()); int index1, index2, index3; std::vector<float> d2v, d1v, d3v, wt_d3; std::vector<int> wt_d2; d1v.reserve (sample_size); d2v.reserve (sample_size * 3); d3v.reserve (sample_size); wt_d2.reserve (sample_size * 3); wt_d3.reserve (sample_size); float h_in[binsize] = {0}; float h_out[binsize] = {0}; float h_mix[binsize] = {0}; float h_mix_ratio[binsize] = {0}; float h_a3_in[binsize] = {0}; float h_a3_out[binsize] = {0}; float h_a3_mix[binsize] = {0}; float h_d1[binsize] = {0}; float h_d3_in[binsize] = {0}; float h_d3_out[binsize] = {0}; float h_d3_mix[binsize] = {0}; float ratio=0.0; float pih = static_cast<float>(M_PI) / 2.0f; float a,b,c,s; int th1,th2,th3; int vxlcnt = 0; int pcnt1,pcnt2,pcnt3; for (size_t nn_idx = 0; nn_idx < sample_size; ++nn_idx) { // get a new random point index1 = rand()%maxindex; index2 = rand()%maxindex; index3 = rand()%maxindex; if (index1==index2 || index1 == index3 || index2 == index3) { nn_idx--; continue; } Eigen::Vector4f p1 = pc.points[index1].getVector4fMap (); Eigen::Vector4f p2 = pc.points[index2].getVector4fMap (); Eigen::Vector4f p3 = pc.points[index3].getVector4fMap (); // A3 Eigen::Vector4f v21 (p2 - p1); Eigen::Vector4f v31 (p3 - p1); Eigen::Vector4f v23 (p2 - p3); a = v21.norm (); b = v31.norm (); c = v23.norm (); s = (a+b+c) * 0.5f; if (s * (s-a) * (s-b) * (s-c) <= 0.001f) continue; v21.normalize (); v31.normalize (); v23.normalize (); //TODO: .dot gives nan's th1 = static_cast<int> (pcl_round (acos (fabs (v21.dot (v31))) / pih * (binsize-1))); th2 = static_cast<int> (pcl_round (acos (fabs (v23.dot (v31))) / pih * (binsize-1))); th3 = static_cast<int> (pcl_round (acos (fabs (v23.dot (v21))) / pih * (binsize-1))); if (th1 < 0 || th1 >= binsize) { nn_idx--; continue; } if (th2 < 0 || th2 >= binsize) { nn_idx--; continue; } if (th3 < 0 || th3 >= binsize) { nn_idx--; continue; } //pcl::PointXYZ cog(((rand()%100)-50.0f) / 100.0f,((rand()%100)-50.0f) / 100.0f,((rand()%100)-50.0f) / 100.0f); // D1 // d1v.push_back( pcl::euclideanDistance(cog, pc.points[index1]) ); // D2 d2v.push_back (pcl::euclideanDistance (pc.points[index1], pc.points[index2])); d2v.push_back (pcl::euclideanDistance (pc.points[index1], pc.points[index3])); d2v.push_back (pcl::euclideanDistance (pc.points[index2], pc.points[index3])); int vxlcnt_sum = 0; int p_cnt = 0; // IN, OUT, MIXED, Ratio line tracing, index1->index2 { const int xs = p1[0] < 0.0? static_cast<int>(floor(p1[0])+GRIDSIZE_H): static_cast<int>(ceil(p1[0])+GRIDSIZE_H-1); const int ys = p1[1] < 0.0? static_cast<int>(floor(p1[1])+GRIDSIZE_H): static_cast<int>(ceil(p1[1])+GRIDSIZE_H-1); const int zs = p1[2] < 0.0? static_cast<int>(floor(p1[2])+GRIDSIZE_H): static_cast<int>(ceil(p1[2])+GRIDSIZE_H-1); const int xt = p2[0] < 0.0? static_cast<int>(floor(p2[0])+GRIDSIZE_H): static_cast<int>(ceil(p2[0])+GRIDSIZE_H-1); const int yt = p2[1] < 0.0? static_cast<int>(floor(p2[1])+GRIDSIZE_H): static_cast<int>(ceil(p2[1])+GRIDSIZE_H-1); const int zt = p2[2] < 0.0? static_cast<int>(floor(p2[2])+GRIDSIZE_H): static_cast<int>(ceil(p2[2])+GRIDSIZE_H-1); wt_d2.push_back (this->lci (xs, ys, zs, xt, yt, zt, ratio, vxlcnt, pcnt1)); if (wt_d2.back () == 2) h_mix_ratio[static_cast<int> (pcl_round (ratio * (binsize-1)))]++; vxlcnt_sum += vxlcnt; p_cnt += pcnt1; } // IN, OUT, MIXED, Ratio line tracing, index1->index3 { const int xs = p1[0] < 0.0? static_cast<int>(floor(p1[0])+GRIDSIZE_H): static_cast<int>(ceil(p1[0])+GRIDSIZE_H-1); const int ys = p1[1] < 0.0? static_cast<int>(floor(p1[1])+GRIDSIZE_H): static_cast<int>(ceil(p1[1])+GRIDSIZE_H-1); const int zs = p1[2] < 0.0? static_cast<int>(floor(p1[2])+GRIDSIZE_H): static_cast<int>(ceil(p1[2])+GRIDSIZE_H-1); const int xt = p3[0] < 0.0? static_cast<int>(floor(p3[0])+GRIDSIZE_H): static_cast<int>(ceil(p3[0])+GRIDSIZE_H-1); const int yt = p3[1] < 0.0? static_cast<int>(floor(p3[1])+GRIDSIZE_H): static_cast<int>(ceil(p3[1])+GRIDSIZE_H-1); const int zt = p3[2] < 0.0? static_cast<int>(floor(p3[2])+GRIDSIZE_H): static_cast<int>(ceil(p3[2])+GRIDSIZE_H-1); wt_d2.push_back (this->lci (xs, ys, zs, xt, yt, zt, ratio, vxlcnt, pcnt2)); if (wt_d2.back () == 2) h_mix_ratio[static_cast<int>(pcl_round (ratio * (binsize-1)))]++; vxlcnt_sum += vxlcnt; p_cnt += pcnt2; } // IN, OUT, MIXED, Ratio line tracing, index2->index3 { const int xs = p2[0] < 0.0? static_cast<int>(floor(p2[0])+GRIDSIZE_H): static_cast<int>(ceil(p2[0])+GRIDSIZE_H-1); const int ys = p2[1] < 0.0? static_cast<int>(floor(p2[1])+GRIDSIZE_H): static_cast<int>(ceil(p2[1])+GRIDSIZE_H-1); const int zs = p2[2] < 0.0? static_cast<int>(floor(p2[2])+GRIDSIZE_H): static_cast<int>(ceil(p2[2])+GRIDSIZE_H-1); const int xt = p3[0] < 0.0? static_cast<int>(floor(p3[0])+GRIDSIZE_H): static_cast<int>(ceil(p3[0])+GRIDSIZE_H-1); const int yt = p3[1] < 0.0? static_cast<int>(floor(p3[1])+GRIDSIZE_H): static_cast<int>(ceil(p3[1])+GRIDSIZE_H-1); const int zt = p3[2] < 0.0? static_cast<int>(floor(p3[2])+GRIDSIZE_H): static_cast<int>(ceil(p3[2])+GRIDSIZE_H-1); wt_d2.push_back (this->lci (xs,ys,zs,xt,yt,zt,ratio,vxlcnt,pcnt3)); if (wt_d2.back () == 2) h_mix_ratio[static_cast<int>(pcl_round(ratio * (binsize-1)))]++; vxlcnt_sum += vxlcnt; p_cnt += pcnt3; } // D3 ( herons formula ) d3v.push_back (sqrt (sqrt (s * (s-a) * (s-b) * (s-c)))); if (vxlcnt_sum <= 21) { wt_d3.push_back (0); h_a3_out[th1] += static_cast<float> (pcnt3) / 32.0f; h_a3_out[th2] += static_cast<float> (pcnt1) / 32.0f; h_a3_out[th3] += static_cast<float> (pcnt2) / 32.0f; } else if (p_cnt - vxlcnt_sum < 4) { h_a3_in[th1] += static_cast<float> (pcnt3) / 32.0f; h_a3_in[th2] += static_cast<float> (pcnt1) / 32.0f; h_a3_in[th3] += static_cast<float> (pcnt2) / 32.0f; wt_d3.push_back (1); } else { h_a3_mix[th1] += static_cast<float> (pcnt3) / 32.0f; h_a3_mix[th2] += static_cast<float> (pcnt1) / 32.0f; h_a3_mix[th3] += static_cast<float> (pcnt2) / 32.0f; wt_d3.push_back (static_cast<float> (vxlcnt_sum) / static_cast<float> (p_cnt)); } } // Normalizing, get max float maxd1 = 0; float maxd2 = 0; float maxd3 = 0; for (size_t nn_idx = 0; nn_idx < sample_size; ++nn_idx) { // get max of Dx if (d1v[nn_idx] > maxd1) maxd1 = d1v[nn_idx]; if (d2v[nn_idx] > maxd2) maxd2 = d2v[nn_idx]; if (d2v[sample_size + nn_idx] > maxd2) maxd2 = d2v[sample_size + nn_idx]; if (d2v[sample_size*2 +nn_idx] > maxd2) maxd2 = d2v[sample_size*2 +nn_idx]; if (d3v[nn_idx] > maxd3) maxd3 = d3v[nn_idx]; } // Normalize and create histogram int index; for (size_t nn_idx = 0; nn_idx < sample_size; ++nn_idx) { h_d1[static_cast<int>(pcl_round (d1v[nn_idx] / maxd1 * (binsize-1)))]++ ; if (wt_d3[nn_idx] >= 0.999) // IN { index = static_cast<int>(pcl_round (d3v[nn_idx] / maxd3 * (binsize-1))); if (index >= 0 && index < binsize) h_d3_in[index]++; } else { if (wt_d3[nn_idx] <= 0.001) // OUT { index = static_cast<int>(pcl_round (d3v[nn_idx] / maxd3 * (binsize-1))); if (index >= 0 && index < binsize) h_d3_out[index]++ ; } else { index = static_cast<int>(pcl_round (d3v[nn_idx] / maxd3 * (binsize-1))); if (index >= 0 && index < binsize) h_d3_mix[index]++; } } } //normalize and create histogram for (size_t nn_idx = 0; nn_idx < d2v.size(); ++nn_idx ) { if (wt_d2[nn_idx] == 0) h_in[static_cast<int>(pcl_round (d2v[nn_idx] / maxd2 * (binsize-1)))]++ ; if (wt_d2[nn_idx] == 1) h_out[static_cast<int>(pcl_round (d2v[nn_idx] / maxd2 * (binsize-1)))]++; if (wt_d2[nn_idx] == 2) h_mix[static_cast<int>(pcl_round (d2v[nn_idx] / maxd2 * (binsize-1)))]++ ; } //float weights[10] = {1, 1, 1, 1, 1, 1, 1, 1 , 1 , 1}; float weights[10] = {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f}; hist.reserve (binsize * 10); for (int i = 0; i < binsize; i++) hist.push_back (h_a3_in[i] * weights[0]); for (int i = 0; i < binsize; i++) hist.push_back (h_a3_out[i] * weights[1]); for (int i = 0; i < binsize; i++) hist.push_back (h_a3_mix[i] * weights[2]); for (int i = 0; i < binsize; i++) hist.push_back (h_d3_in[i] * weights[3]); for (int i = 0; i < binsize; i++) hist.push_back (h_d3_out[i] * weights[4]); for (int i = 0; i < binsize; i++) hist.push_back (h_d3_mix[i] * weights[5]); for (int i = 0; i < binsize; i++) hist.push_back (h_in[i]*0.5f * weights[6]); for (int i = 0; i < binsize; i++) hist.push_back (h_out[i] * weights[7]); for (int i = 0; i < binsize; i++) hist.push_back (h_mix[i] * weights[8]); for (int i = 0; i < binsize; i++) hist.push_back (h_mix_ratio[i]*0.5f * weights[9]); float sm = 0; for (size_t i = 0; i < hist.size (); i++) sm += hist[i]; for (size_t i = 0; i < hist.size (); i++) hist[i] /= sm; }
int main(int argc, char *argv[]) { Pooma::initialize(argc,argv); Pooma::Tester tester(argc, argv); // -------------------------------------------------------------------------- // 3D // -------------------------------------------------------------------------- Tensor<3,double,Full> t3f1(0.0, 3.0, 6.0, 1.0, 4.0, 7.0, 2.0, 5.0, 8.0); tester.out() << "t3f1: " << t3f1 << std::endl; Tensor<3,double,Full> t3f2 = -t3f1; tester.out() << "t3f2: " << t3f2 << std::endl; Tensor<3,double,Symmetric> t3s1(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); tester.out() << "t3s1: " << t3s1 << std::endl; Tensor<3,double,Symmetric> t3s2(-1.0, -2.0, -3.0, -4.0, -5.0, -6.0); tester.out() << "t3s2: " << t3s2 << std::endl; Tensor<3,double,Full> t3s1AsFull(1.0,2.0,4.0, 2.0,3.0,5.0, 4.0,5.0,6.0); tester.out() << "t3s1AsFull: " << t3s1AsFull << std::endl; Tensor<3,double,Full> t3s2AsFull = -t3s1AsFull; tester.out() << "t3s2AsFull: " << t3s2AsFull << std::endl; Tensor<3,double,Symmetric> t3s3(9.0, 9.0, 9.0, 9.0, 9.0, 9.0), t3s4(9.0, 9.0, 9.0, 9.0, 9.0, 9.0); t3s3 = t3s1 + t3s2; tester.out() << "t3s3 = t3s1 + t3s2: " << t3s3 << std::endl; tester.check("t3s3", t3s3, Tensor<3,double,Symmetric>(0.0)); tester.check("t3s3 against Full", (t3s3 == Tensor<3,double,Symmetric>(0.0))); Tensor<3,double,Full> t3f3(99.9), t3f4(99.9), t3f5(99.9), t3f6(99.9); t3f3 = t3f1 + t3f2; // No need to check results here; done in TestTensors t3f4 = t3s1 + t3s2; tester.out() << "t3f4 = t3s1 + t3s2: " << t3f4 << std::endl; tester.check("t3f4", (t3f4 == t3s3)); t3f5 = t3f1 + t3s2; tester.out() << "t3f5 = t3f1 + t3s2: " << t3f5 << std::endl; tester.check("t3f5", t3f5, t3f1 + t3s2AsFull); t3f6 = t3s2 + t3f1; tester.out() << "t3f6 = t3s2 + t3f1: " << t3f6 << std::endl; tester.check("t3f6", t3f6, t3f1 + t3s2AsFull); t3f6 -= t3f1; tester.out() << "t3f6 -= t3f1: " << t3f6 << std::endl; tester.check("t3f6", t3f6, t3s2AsFull); t3s4 = t3s3 - t3f1; tester.out() << "t3s4 = t3s3 - t3f1: " << t3s4 << std::endl; tester.check("t3s4", (t3s4 == Tensor<3,double,Symmetric>(0,-3,-4,-6,-7,-8))); // Test Tensor dot Tensor: // Full: double sum = 0.0; int i, j, k; t3f3 = dot(t3f1, t3f2); for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { for (k = 0; k < 3; ++k) { t3f3(i,k) -= t3f1(i,j)*t3f2(j,k); } } } t3f3 = t3f3*t3f3; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { sum += t3f3(i,j); } } tester.check("dot(t3f1, t3f2)", (sum == 0)); // Symmetric: sum = 0.0; t3f3 = dot(t3s1, t3s2); for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { for (k = 0; k < 3; ++k) { t3f3(i,k) -= t3s1(i,j)*t3s2(j,k); } } } t3f3 = t3f3*t3f3; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { sum += t3f3(i,j); } } tester.check("dot(t3s1, t3s2)", (sum == 0)); // Test Tensor dot Vector, and vice-versa: // Full: // Vector dot Tensor Vector<3> v31(1.0, 2.0, 3.0); tester.out() << "v31: " << v31 << std::endl; Vector<3> v32(9.0); v32 = dot(v31, t3f2); tester.out() << "v32 = dot(v31, t3f2): " << v32 << std::endl; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { v32(j) -= v31(i)*t3f2(i,j); } } v32 = v32*v32; sum = 0.0; for (i = 0; i < 3; ++i) { sum += v32(i); } tester.check("dot(v31, t3f2)", (sum == 0)); // Tensor dot Vector v32 = dot(t3f2, v31); tester.out() << "v32 = dot(t3f2, v31): " << v32 << std::endl; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { v32(i) -= t3f2(i,j)*v31(j); } } v32 = v32*v32; sum = 0.0; for (i = 0; i < 3; ++i) { sum += v32(i); } tester.check("dot(t3f2, v31)", (sum == 0)); // Symmetric: // Vector dot Tensor v32 = dot(v31, t3s2); tester.out() << "v32 = dot(v31, t3s2): " << v32 << std::endl; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { v32(j) -= v31(i)*t3s2(i,j); } } v32 = v32*v32; sum = 0.0; for (i = 0; i < 3; ++i) { sum += v32(i); } tester.check("dot(v31, t3s2)", (sum == 0)); // Tensor dot Vector v32 = dot(t3s2, v31); tester.out() << "v32 = dot(t3s2, v31): " << v32 << std::endl; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { v32(i) -= t3s2(i,j)*v31(j); } } v32 = v32*v32; sum = 0.0; for (i = 0; i < 3; ++i) { sum += v32(i); } tester.check("dot(t3s2, v31)", (sum == 0)); // -------------------------------------------------------------------------- // 2D // -------------------------------------------------------------------------- Tensor<2,double,Full> t2f1(0.0, 2.0, 1.0, 3.0); tester.out() << "t2f1: " << t2f1 << std::endl; Tensor<2,double,Full> t2f2 = -t2f1; tester.out() << "t2f2: " << t2f2 << std::endl; Tensor<2,double,Symmetric> t2s1(1.0, 2.0, 3.0); tester.out() << "t2s1: " << t2s1 << std::endl; Tensor<2,double,Symmetric> t2s2(-1.0, -2.0, -3.0); tester.out() << "t2s2: " << t2s2 << std::endl; Tensor<2,double,Full> t2s1AsFull(1.0,2.0, 2.0,3.0); tester.out() << "t2s1AsFull: " << t2s1AsFull << std::endl; Tensor<2,double,Full> t2s2AsFull = -t2s1AsFull; tester.out() << "t2s2AsFull: " << t2s2AsFull << std::endl; Tensor<2,double,Symmetric> t2s3(9.0, 9.0, 9.0), t2s4(9.0, 9.0, 9.0); t2s3 = t2s1 + t2s2; tester.out() << "t2s3 = t2s1 + t2s2: " << t2s3 << std::endl; tester.check("t2s3", t2s3, Tensor<2,double,Symmetric>(0.0)); tester.check("t2s3 against Full", (t2s3 == Tensor<2,double,Symmetric>(0.0))); Tensor<2,double,Full> t2f3(99.9), t2f4(99.9), t2f5(99.9), t2f6(99.9), t2f7(99.9); t2f3 = t2f1 + t2f2; tester.out() << "t2f3 = t2f1 + t2f2: " << t2f3 << std::endl; tester.check("t2f3", t2f3, Tensor<2,double,Full>(0.0)); t2f4 = t2s1 + t2s2; tester.out() << "t2f4 = t2s1 + t2s2: " << t2f4 << std::endl; tester.check("t2f4", (t2f4 == t2s3)); t2f5 = t2f1 + t2s2; tester.out() << "t2f5 = t2f1 + t2s2: " << t2f5 << std::endl; tester.check("t2f5", t2f5, t2f1 + t2s2AsFull); t2f6 = t2s2 + t2f1; tester.out() << "t2f6 = t2s2 + t2f1: " << t2f6 << std::endl; tester.check("t2f6", t2f6, t2f1 + t2s2AsFull); t2f6 -= t2f1; tester.out() << "t2f6 -= t2f1: " << t2f6 << std::endl; tester.check("t2f6", t2f6, t2s2AsFull); t2s4 = t2s3 - t2f1; tester.out() << "t2s4 = t2s3 - t2f1: " << t2s4 << std::endl; tester.check("t2s4", (t2s4 == Tensor<2,double,Symmetric>(-0, -2, -3))); // Test Tensor dot Tensor: // Full: sum = 0.0; t2f3 = dot(t2f1, t2f2); for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { for (k = 0; k < 2; ++k) { t2f3(i,k) -= t2f1(i,j)*t2f2(j,k); } } } t2f3 = t2f3*t2f3; for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { sum += t2f3(i,j); } } tester.check("dot(t2f1, t2f2)", (sum == 0)); // Symmetric: sum = 0.0; t2f3 = dot(t2s1, t2s2); for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { for (k = 0; k < 2; ++k) { t2f3(i,k) -= t2s1(i,j)*t2s2(j,k); } } } t2f3 = t2f3*t2f3; for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { sum += t2f3(i,j); } } tester.check("dot(t2s1, t2s2)", (sum == 0)); // Test Tensor dot Vector, and vice-versa: // Full: // Vector dot Tensor Vector<2> v21(1.0, 2.0); tester.out() << "v21: " << v21 << std::endl; Vector<2> v22(9.0); v22 = dot(v21, t2f2); tester.out() << "v22 = dot(v21, t2f2): " << v22 << std::endl; for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { v22(j) -= v21(i)*t2f2(i,j); } } v22 = v22*v22; sum = 0.0; for (i = 0; i < 2; ++i) { sum += v22(i); } tester.check("dot(v21, t2f2)", (sum == 0)); // Tensor dot Vector v22 = dot(t2f2, v21); tester.out() << "v22 = dot(t2f2, v21): " << v22 << std::endl; for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { v22(i) -= t2f2(i,j)*v21(j); } } v22 = v22*v22; sum = 0.0; for (i = 0; i < 2; ++i) { sum += v22(i); } tester.check("dot(t2f2, v21)", (sum == 0)); // Symmetric: // Vector dot Tensor v22 = dot(v21, t2s2); tester.out() << "v22 = dot(v21, t2s2): " << v22 << std::endl; for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { v22(j) -= v21(i)*t2s2(i,j); } } v22 = v22*v22; sum = 0.0; for (i = 0; i < 2; ++i) { sum += v22(i); } tester.check("dot(v21, t2s2)", (sum == 0)); // Tensor dot Vector v22 = dot(t2s2, v21); tester.out() << "v22 = dot(t2s2, v21): " << v22 << std::endl; for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { v22(i) -= t2s2(i,j)*v21(j); } } v22 = v22*v22; sum = 0.0; for (i = 0; i < 2; ++i) { sum += v22(i); } tester.check("dot(t2s2, v21)", (sum == 0)); // -------------------------------------------------------------------------- // 1D // -------------------------------------------------------------------------- Tensor<1,double,Full> t1f1(1.0); tester.out() << "t1f1: " << t1f1 << std::endl; Tensor<1,double,Full> t1f2 = -t1f1; tester.out() << "t1f2: " << t1f2 << std::endl; Tensor<1,double,Symmetric> t1s1(1.0); tester.out() << "t1s1: " << t1s1 << std::endl; Tensor<1,double,Symmetric> t1s2(-1.0); tester.out() << "t1s2: " << t1s2 << std::endl; Tensor<1,double,Full> t1s1AsFull(1.0); tester.out() << "t1s1AsFull: " << t1s1AsFull << std::endl; Tensor<1,double,Full> t1s2AsFull = -t1s1AsFull; tester.out() << "t1s2AsFull: " << t1s2AsFull << std::endl; Tensor<1,double,Symmetric> t1s3(9.0), t1s4(9.0); t1s3 = t1s1 + t1s2; tester.out() << "t1s3 = t1s1 + t1s2: " << t1s3 << std::endl; tester.check("t1s3", t1s3, Tensor<1,double,Symmetric>(0.0)); tester.check("t1s3 against Full", (t1s3 == Tensor<1,double,Symmetric>(0.0))); Tensor<1,double,Full> t1f3(99.9), t1f4(99.9), t1f5(99.9), t1f6(99.9), t1f7(99.9); t1f3 = t1f1 + t1f2; tester.out() << "t1f3 = t1f1 + t1f2: " << t1f3 << std::endl; tester.check("t1f3", t1f3, Tensor<1,double,Full>(0.0)); t1f4 = t1s1 + t1s2; tester.out() << "t1f4 = t1s1 + t1s2: " << t1f4 << std::endl; tester.check("t1f4", (t1f4 == t1s3)); t1f5 = t1f1 + t1s2; tester.out() << "t1f5 = t1f1 + t1s2: " << t1f5 << std::endl; tester.check("t1f5", t1f5, t1f1 + t1s2AsFull); t1f6 = t1s2 + t1f1; tester.out() << "t1f6 = t1s2 + t1f1: " << t1f6 << std::endl; tester.check("t1f6", t1f6, t1f1 + t1s2AsFull); t1f6 -= t1f1; tester.out() << "t1f6 -= t1f1: " << t1f6 << std::endl; tester.check("t1f6", t1f6, t1s2AsFull); t1s4 = t1s3 - t1f1; tester.out() << "t1s4 = t1s3 - t1f1: " << t1s4 << std::endl; tester.check("t1s4", (t1s4 == Tensor<1,double,Symmetric>(-1))); // Test Tensor dot Tensor: // Full: sum = 0.0; t1f3 = dot(t1f1, t1f2); for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { for (k = 0; k < 1; ++k) { t1f3(i,k) -= t1f1(i,j)*t1f2(j,k); } } } t1f3 = t1f3*t1f3; for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { sum += t1f3(i,j); } } tester.check("dot(t1f1, t1f2)", (sum == 0)); // Symmetric: sum = 0.0; t1f3 = dot(t1s1, t1s2); for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { for (k = 0; k < 1; ++k) { t1f3(i,k) -= t1s1(i,j)*t1s2(j,k); } } } t1f3 = t1f3*t1f3; for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { sum += t1f3(i,j); } } tester.check("dot(t1s1, t1s2)", (sum == 0)); // Test Tensor dot Vector, and vice-versa: // Full: // Vector dot Tensor Vector<1> v11(1.0); tester.out() << "v11: " << v11 << std::endl; Vector<1> v12(9.0); v12 = dot(v11, t1f2); tester.out() << "v12 = dot(v11, t1f2): " << v12 << std::endl; for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { v12(j) -= v11(i)*t1f2(i,j); } } v12 = v12*v12; sum = 0.0; for (i = 0; i < 1; ++i) { sum += v12(i); } tester.check("dot(v11, t1f2)", (sum == 0)); // Tensor dot Vector v12 = dot(t1f2, v11); tester.out() << "v12 = dot(t1f2, v11): " << v12 << std::endl; for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { v12(i) -= t1f2(i,j)*v11(j); } } v12 = v12*v12; sum = 0.0; for (i = 0; i < 1; ++i) { sum += v12(i); } tester.check("dot(t1f2, v11)", (sum == 0)); // Symmetric: // Vector dot Tensor v12 = dot(v11, t1s2); tester.out() << "v12 = dot(v11, t1s2): " << v12 << std::endl; for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { v12(j) -= v11(i)*t1s2(i,j); } } v12 = v12*v12; sum = 0.0; for (i = 0; i < 1; ++i) { sum += v12(i); } tester.check("dot(v11, t1s2)", (sum == 0)); // Tensor dot Vector v12 = dot(t1s2, v11); tester.out() << "v12 = dot(t1s2, v11): " << v12 << std::endl; for (i = 0; i < 1; ++i) { for (j = 0; j < 1; ++j) { v12(i) -= t1s2(i,j)*v11(j); } } v12 = v12*v12; sum = 0.0; for (i = 0; i < 1; ++i) { sum += v12(i); } tester.check("dot(t1s2, v11)", (sum == 0)); int ret = tester.results("TestSymmetricTensors"); Pooma::finalize(); return ret; }
osg::Drawable *ClampNode::createBrick(void) const { // Get the brick Clamp* clamp = static_cast<Clamp*>(_lego); // Get brick color QColor color = clamp->getColor(); // Get clamp bounding box clamp->calculateBoundingBox(); BoundingBox bb = clamp->getBoundingBox(); // Get integer sizes int width = bb.getWidth(); int length = bb.getLength(); int height = bb.getHeight(); // Get real position, according to tile size double mw = (-width)*Lego::length_unit/2; double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2; double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit; double pw = (width)*Lego::length_unit/2; double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2; double ml = (-length)*Lego::length_unit/2; double mlp = (-length+0.5)*Lego::length_unit/2; double pl = (length)*Lego::length_unit/2; double plm = (length-0.5)*Lego::length_unit/2; double mh = (-height)*Lego::height_unit/2; double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height; double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height; double phm = (height)*Lego::height_unit/2-Lego::height_unit/2; double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2; // Create 3 vertices osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; osg::Vec3 v0(ml, mw, mh); osg::Vec3 v1(pl, mw, mh); osg::Vec3 v2(pl, pw, mh); osg::Vec3 v3(ml, pw, mh); osg::Vec3 v4(ml, pw, mhp); osg::Vec3 v5(pl, pw, mhp); osg::Vec3 v6(pl, mw, mhp); osg::Vec3 v7(ml, mw, mhp); osg::Vec3 v8(mlp, mw, mhp); osg::Vec3 v9(mlp, mw, phm); osg::Vec3 v10(ml, mw, phm); osg::Vec3 v11(ml, mwp, phmp); osg::Vec3 v12(mlp, mwp, phmp); osg::Vec3 v13(mlp, pw, mhp); osg::Vec3 v14(plm, mw, mhp); osg::Vec3 v15(plm, mw, phm); osg::Vec3 v16(pl, mw, phm); osg::Vec3 v17(pl, mwp, phmp); osg::Vec3 v18(plm, mwp, phmp); osg::Vec3 v19(plm, pw, mhp); osg::Vec3 v20(mlp, mwpm, mh); osg::Vec3 v21(plm, mwpm, mh); osg::Vec3 v22(plm, pwm, mh); osg::Vec3 v23(mlp, pwm, mh); osg::Vec3 v24(mlp, mwpm, mhpm); osg::Vec3 v25(plm, mwpm, mhpm); osg::Vec3 v26(plm, pwm, mhpm); osg::Vec3 v27(mlp, pwm, mhpm); // Create 1 faces, 0 faces are quads splitted into two triangles // NB: Down face is transparent, we don't even create it // Bottom vertices->push_back(v3); vertices->push_back(v2); vertices->push_back(v1); vertices->push_back(v0); // Bottom hole vertices->push_back(v20); vertices->push_back(v21); vertices->push_back(v22); vertices->push_back(v23); // Bottom far vertices->push_back(v24); vertices->push_back(v25); vertices->push_back(v26); vertices->push_back(v27); // Front face vertices->push_back(v2); vertices->push_back(v3); vertices->push_back(v4); vertices->push_back(v5); // Back face vertices->push_back(v0); vertices->push_back(v1); vertices->push_back(v6); vertices->push_back(v7); // Left bottom face vertices->push_back(v0); vertices->push_back(v3); vertices->push_back(v4); vertices->push_back(v7); // Right bottom face vertices->push_back(v1); vertices->push_back(v2); vertices->push_back(v5); vertices->push_back(v6); // Top face vertices->push_back(v4); vertices->push_back(v5); vertices->push_back(v6); vertices->push_back(v7); // Left part back vertices->push_back(v7); vertices->push_back(v8); vertices->push_back(v9); vertices->push_back(v10); // Left part left ext vertices->push_back(v4); vertices->push_back(v7); vertices->push_back(v10); vertices->push_back(v11); // Left part front vertices->push_back(v4); vertices->push_back(v11); vertices->push_back(v12); vertices->push_back(v13); // Left part left int vertices->push_back(v8); vertices->push_back(v9); vertices->push_back(v12); vertices->push_back(v13); // Right part back vertices->push_back(v6); vertices->push_back(v14); vertices->push_back(v15); vertices->push_back(v16); // Left part left ext vertices->push_back(v5); vertices->push_back(v6); vertices->push_back(v16); vertices->push_back(v17); // Left part front vertices->push_back(v5); vertices->push_back(v17); vertices->push_back(v18); vertices->push_back(v19); // Left part left int vertices->push_back(v14); vertices->push_back(v15); vertices->push_back(v18); vertices->push_back(v19); // Bottom front vertices->push_back(v20); vertices->push_back(v21); vertices->push_back(v25); vertices->push_back(v24); // Bottom right vertices->push_back(v21); vertices->push_back(v22); vertices->push_back(v26); vertices->push_back(v25); // Bottom back vertices->push_back(v22); vertices->push_back(v23); vertices->push_back(v27); vertices->push_back(v26); // Bottom left vertices->push_back(v23); vertices->push_back(v20); vertices->push_back(v24); vertices->push_back(v27); // Create tile geometry osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry; // Match vertices clampGeometry->setVertexArray(vertices); // Create colors osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; // Every face has the same color, so there is only one color colors->push_back(osgColor); // Match color clampGeometry->setColorArray(colors); clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); // Create normals osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0, 0, -1)); normals->push_back(osg::Vec3(0, 0, -1)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(0, 0, 1)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); double w = pw - mwp; double h = phmp - mhp; double norm = std::sqrt(w*w + h*h); normals->push_back(osg::Vec3(0, h/norm, w/norm)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(0, h/norm, w/norm)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(1, 0, 0)); // Match normals clampGeometry->setNormalArray(normals); clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4)); // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4)); // Retesslate to create hole osgUtil::Tessellator tesslator; tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD); tesslator.retessellatePolygons(*clampGeometry); // Create 17 GL_QUADS, i.e. 18*4 vertices clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4)); // Return the tile whithout plot return clampGeometry.release(); }