// ------------------------------------------------------------------------------- // CREATETRIXELCHILD // Check if trixel children structure already exists // Assert for given <index> // Check if select child does not exist // Create new vertices on side midpoints // Set vertices that defines the new subtrixel // else display a message // return the pointer trixel* CreateTrixelChild(trixel* parent, unsigned short int& index) { if (parent->_children == NULL) { llog::debug["ICoDF::CreateTrixelChild"] << "Trixel has no container for children" << std::endl; CreateTrixelChildren(parent); } assert(index < 4); if (parent->_children[index] == NULL) { parent->_children[index] = new trixel(); InitTrixel(parent->_children[index]); parent->_children[index]->_HTMId = parent->_HTMId + std::to_string(index); Eigen::Vector3d* midPoints = ComputeTrixelMidpoints(parent); switch (index) { case 0: parent->_children[index]->_vertices[0] = parent->_vertices[0]; parent->_children[index]->_vertices[1] = midPoints[2]; parent->_children[index]->_vertices[2] = midPoints[1]; break; case 1: parent->_children[index]->_vertices[0] = parent->_vertices[1]; parent->_children[index]->_vertices[1] = midPoints[0]; parent->_children[index]->_vertices[2] = midPoints[2]; break; case 2: parent->_children[index]->_vertices[0] = parent->_vertices[2]; parent->_children[index]->_vertices[1] = midPoints[1]; parent->_children[index]->_vertices[2] = midPoints[0]; break; case 3: parent->_children[index]->_vertices[0] = midPoints[0]; parent->_children[index]->_vertices[1] = midPoints[1]; parent->_children[index]->_vertices[2] = midPoints[2]; break; default: llog::warn["ICoDF::CreateTrixelChild"] << "Given <index> is out of bound" << std::endl; delete [] midPoints; return NULL; } delete [] midPoints; } else { llog::warn["ICoDF::CreateTrixelChild"] << "SubTrixel [" << parent->_HTMId << index << "] already exists" << std::endl; } return parent->_children[index]; }
// ------------------------------------------------------------------------------- // CREATETRIXELCHILD // Check if trixel children structure already exists // Assert for given <index> // Check if select child does not exist // Create new vertices on side midpoints // Set vertices that defines the new subtrixel // else display a message // return the pointer trixel_t* ICoDF_HTM::CreateTrixelChild(trixel_t* parent, unsigned short int& index) { if (parent->_children == NULL) { LS_ADDMSG(LogService::NOTICE, "ICoDF::CreateTrixelChild", "Trixel as no container for children"); CreateTrixelChildren(parent); } assert(index < 4); if (parent->_children[index] == NULL) { std::stringstream tmp; parent->_children[index] = new trixel_t(); InitTrixel(parent->_children[index]); tmp.str(""); tmp << parent->_HTMId << index; parent->_children[index]->_HTMId = tmp.str(); Vector3d midPoints[3]; ComputeTrixelMidpoints(parent, midPoints); switch (index) { case 0: parent->_children[index]->_vertices[0] = parent->_vertices[0]; parent->_children[index]->_vertices[1] = midPoints[2]; parent->_children[index]->_vertices[2] = midPoints[1]; break; case 1: parent->_children[index]->_vertices[0] = parent->_vertices[1]; parent->_children[index]->_vertices[1] = midPoints[0]; parent->_children[index]->_vertices[2] = midPoints[2]; break; case 2: parent->_children[index]->_vertices[0] = parent->_vertices[2]; parent->_children[index]->_vertices[1] = midPoints[1]; parent->_children[index]->_vertices[2] = midPoints[0]; break; case 3: parent->_children[index]->_vertices[0] = midPoints[0]; parent->_children[index]->_vertices[1] = midPoints[1]; parent->_children[index]->_vertices[2] = midPoints[2]; break; default: LS_ADDMSG(LogService::FATAL, "ICoDF::CreateTrixelChild", "Given <index> is out of bound"); return NULL; } } else { std::stringstream tmp; tmp << "SubTrixel [" << parent->_HTMId << index << "] already exists"; LS_ADDMSG(LogService::NOTICE, "ICoDF::CreateTrixelChild", tmp.str()); } return parent->_children[index]; }
// -------------------------------------------------------------------- // GETINDEX (vector version) unsigned short int GetIndex(trixel* trixel, Eigen::Vector3d& p) { if (trixel != NULL && NULL != trixel->_vertices) { unsigned short int index = max<unsigned short int>(); Eigen::Vector3d* v = trixel->_vertices; Eigen::Vector3d* w = ComputeTrixelMidpoints(trixel); // HERE // Here WHAT ??! if (v[0].cross(w[2]).dot(p) > 0 && w[2].cross(w[1]).dot(p) > 0 && w[1].cross(v[0]).dot(p) > 0) index = 0; else if (v[1].cross(w[0]).dot(p) > 0 && w[0].cross(w[2]).dot(p) > 0 && w[2].cross(v[1]).dot(p) > 0) index = 1; else if (v[2].cross(w[1]).dot(p) > 0 && w[1].cross(w[0]).dot(p) > 0 && w[0].cross(v[2]).dot(p) > 0) index = 2; else if (w[0].cross(w[1]).dot(p) > 0 && w[1].cross(w[2]).dot(p) > 0 && w[2].cross(w[0]).dot(p) > 0) index = 3; if (index == max<unsigned short>()) // Shit is incorrect, but why, what, how ? God only knows llog::warn["GetIndex"] << "Incorrect : " << trixel->_HTMId << std::endl << "--- v1" << std::endl << trixel->_vertices[0] << std::endl << "--- v2" << std::endl << trixel->_vertices[1] << std::endl << "--- v3" << std::endl << trixel->_vertices[2] << std::endl << "--- p" << std::endl << p << std::endl; delete [] w; return index; } else { llog::warn["GetIndex"] << "Given <trixel> or its vertices has a NULL value" << std::endl; return max<unsigned short>(); } }
// -------------------------------------------------------------------- // GETINDEX (vector version) unsigned short int ICoDF_HTM::GetIndex(trixel_t* trixel, Vector3d& p) { if (trixel != NULL && NULL != trixel->_vertices) { unsigned short int index = (unsigned short int)~0; Vector3d* v = trixel->_vertices; Vector3d w[3]; ComputeTrixelMidpoints(trixel, w); // HERE if (v[0].cross(w[2]).dot(p) > 0 && w[2].cross(w[1]).dot(p) > 0 && w[1].cross(v[0]).dot(p) > 0) index = 0; else if (v[1].cross(w[0]).dot(p) > 0 && w[0].cross(w[2]).dot(p) > 0 && w[2].cross(v[1]).dot(p) > 0) index = 1; else if (v[2].cross(w[1]).dot(p) > 0 && w[1].cross(w[0]).dot(p) > 0 && w[0].cross(v[2]).dot(p) > 0) index = 2; else if (w[0].cross(w[1]).dot(p) > 0 && w[1].cross(w[2]).dot(p) > 0 && w[2].cross(w[0]).dot(p) > 0) index = 3; return index; } else { LS_ADDMSG(LogService::WARNING, "ICoDF_HTM::GetIndex", "Given <trixel> or its vertices has a NULL value"); return (unsigned short int)~0; } }