void ribi::foam::FacesFileItem::Test() noexcept { { static bool is_tested = false; if (is_tested) return; is_tested = true; } TRACE("Starting ribi::foam::FacesFileItem::Test"); const FacesFileItem i( { PointIndex(1),PointIndex(2),PointIndex(3),PointIndex(4) } ); std::stringstream s; s << i; FacesFileItem j; s >> j; if (i != j) { TRACE(i); TRACE(j); } assert(i == j); TRACE("Finished ribi::foam::FacesFileItem::Test successfully"); }
const boost::shared_ptr<ribi::foam::FacesFile> ribi::foam::Mesh::CreateFaces() const noexcept { std::vector<FacesFileItem> items; //std::vector<boost::shared_ptr<const ribi::foam::Face>> faces; std::transform( m_faces.begin(), m_faces.end(), std::back_inserter(items), [this](const boost::shared_ptr<const Face> face) { assert(face); const std::vector<boost::shared_ptr<const ribi::Coordinat3D> > points { face->GetPoints() }; std::vector<PointIndex> point_indices; std::transform(points.begin(),points.end(), std::back_inserter(point_indices), [this](boost::shared_ptr<const ribi::Coordinat3D> coordinat) { const std::vector<boost::shared_ptr<ribi::Coordinat3D>>::const_iterator iter { std::find(m_points.begin(),m_points.end(),coordinat) }; assert(iter != m_points.end()); const int index { std::distance(m_points.begin(),iter) }; assert(index >= 0); assert(index < static_cast<int>(m_points.size())); return PointIndex(index); } ); return FacesFileItem(point_indices); } ); const boost::shared_ptr<FacesFile> f { new FacesFile( FacesFile::GetDefaultHeader(), items ) }; assert(f); return f; }
void WriteDiffPackFormat (const Mesh & mesh, const CSGeometry & geom, const string & filename) { // double scale = globflags.GetNumFlag ("scale", 1); double scale = 1; ofstream outfile(filename.c_str()); if (mesh.GetDimension() == 3) { // Output compatible to Diffpack grid format // Bartosz Sawicki <*****@*****.**> int np = mesh.GetNP(); int ne = mesh.GetNE(); int nse = mesh.GetNSE(); Array <int> BIname; Array <int> BCsinpoint; int i, j, k, l; outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); const Element & eldummy = mesh.VolumeElement((int)1); outfile << "\n\n" "Finite element mesh (GridFE):\n\n" " Number of space dim. = 3\n" " Number of elements = " << ne << "\n" " Number of nodes = " << np << "\n\n" " All elements are of the same type : dpTRUE\n" " Max number of nodes in an element: "<< eldummy.GetNP() << "\n" " Only one subdomain : dpFALSE\n" " Lattice data ? 0\n\n\n\n"; for (i = 1; i <= nse; i++) { int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty(); int nbi=BIname.Size(); int found=0; for (j = 1; j <= nbi; j++) if(BI == BIname.Get(j)) found = 1; if( ! found ) BIname.Append(BI); } outfile << " " << BIname.Size() << " Boundary indicators: "; for (i =1 ; i <= BIname.Size(); i++) outfile << BIname.Get(i) << " "; outfile << "\n\n\n"; outfile << " Nodal coordinates and nodal boundary indicators,\n" " the columns contain:\n" " - node number\n" " - coordinates\n" " - no of boundary indicators that are set (ON)\n" " - the boundary indicators that are set (ON) if any.\n" "#\n"; for (i = 1; i <= np; i++) { const Point3d & p = mesh.Point(i); outfile.width(4); outfile << i << " ("; outfile.width(10); outfile << p.X()/scale << ", "; outfile.width(9); outfile << p.Y()/scale << ", "; outfile.width(9); outfile << p.Z()/scale << ") "; if(mesh[PointIndex(i)].Type() != INNERPOINT) { BCsinpoint.DeleteAll(); for (j = 1; j <= nse; j++) { for (k = 1; k <= mesh.SurfaceElement(j).GetNP(); k++) { if(mesh.SurfaceElement(j).PNum(k)==i) { int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty(); int nbcsp=BCsinpoint.Size(); int found = 0; for (l = 1; l <= nbcsp; l++) if(BC == BCsinpoint.Get(l)) found = 1; if( ! found ) BCsinpoint.Append(BC); } } } int nbcsp = BCsinpoint.Size(); outfile << "[" << nbcsp << "] "; for (j = 1; j <= nbcsp; j++) outfile << BCsinpoint.Get(j) << " "; outfile << "\n"; } else outfile << "[0]\n"; } outfile << "\n" " Element types and connectivity\n" " the columns contain:\n" " - element number\n" " - element type\n" " - subdomain number\n" " - the global node numbers of the nodes in the element.\n" "#\n"; for (i = 1; i <= ne; i++) { const Element & el = mesh.VolumeElement(i); outfile.width(5); if(el.GetNP()==4) outfile << i << " ElmT4n3D "; else outfile << i << " ElmT10n3D "; outfile.width(4); outfile << el.GetIndex() << " "; if(el.GetNP()==10) { outfile.width(8); outfile << el.PNum(1); outfile.width(8); outfile << el.PNum(3); outfile.width(8); outfile << el.PNum(2); outfile.width(8); outfile << el.PNum(4); outfile.width(8); outfile << el.PNum(6); outfile.width(8); outfile << el.PNum(8); outfile.width(8); outfile << el.PNum(5); outfile.width(8); outfile << el.PNum(7); outfile.width(8); outfile << el.PNum(10); outfile.width(8); outfile << el.PNum(9); } else { outfile.width(8); outfile << el.PNum(1); outfile.width(8); outfile << el.PNum(3); outfile.width(8); outfile << el.PNum(2); outfile.width(8); outfile << el.PNum(4); } outfile << "\n"; } } /* Diffpack */ else { // Output compatible to Diffpack grid format 2D int np = mesh.GetNP(); //int ne = mesh.GetNE(); int nse = mesh.GetNSE(); Array <int> BIname; Array <int> BCsinpoint; int i, j, k, l; outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); outfile << "\n\n" "Finite element mesh (GridFE):\n\n" " Number of space dim. = 2\n" " Number of elements = " << nse << "\n" " Number of nodes = " << np << "\n\n" " All elements are of the same type : dpTRUE\n" " Max number of nodes in an element: 3\n" " Only one subdomain : dpFALSE\n" " Lattice data ? 0\n\n\n\n"; for (i = 1; i <= nse; i++) { int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty(); int nbi=BIname.Size(); int found=0; for (j = 1; j <= nbi; j++) if(BI == BIname.Get(j)) found = 1; if( ! found ) BIname.Append(BI); } outfile << " " << BIname.Size() << " Boundary indicators: "; for (i =1 ; i <= BIname.Size(); i++) outfile << BIname.Get(i) << " "; outfile << "\n\n\n"; outfile << " Nodal coordinates and nodal boundary indicators,\n" " the columns contain:\n" " - node number\n" " - coordinates\n" " - no of boundary indicators that are set (ON)\n" " - the boundary indicators that are set (ON) if any.\n" "#\n"; for (i = 1; i <= np; i++) { const Point3d & p = mesh.Point(i); outfile.width(4); outfile << i << " ("; outfile.width(10); outfile << p.X()/scale << ", "; outfile.width(9); outfile << p.Y()/scale << ", "; if(mesh[PointIndex(i)].Type() != INNERPOINT) { BCsinpoint.DeleteAll(); for (j = 1; j <= nse; j++) { for (k = 1; k <= 2; k++) { if(mesh.SurfaceElement(j).PNum(k)==i) { int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty(); int nbcsp=BCsinpoint.Size(); int found = 0; for (l = 1; l <= nbcsp; l++) if(BC == BCsinpoint.Get(l)) found = 1; if( ! found ) BCsinpoint.Append(BC); } } } int nbcsp = BCsinpoint.Size(); outfile << "[" << nbcsp << "] "; for (j = 1; j <= nbcsp; j++) outfile << BCsinpoint.Get(j) << " "; outfile << "\n"; } else outfile << "[0]\n"; } outfile << "\n" " Element types and connectivity\n" " the columns contain:\n" " - element number\n" " - element type\n" " - subdomain number\n" " - the global node numbers of the nodes in the element.\n" "#\n"; for (i = 1; i <= nse; i++) { const Element2d & el = mesh.SurfaceElement(i); outfile.width(5); outfile << i << " ElmT3n2D "; outfile.width(4); outfile << el.GetIndex() << " "; outfile.width(8); outfile << el.PNum(1); outfile.width(8); outfile << el.PNum(3); outfile.width(8); outfile << el.PNum(2); outfile << "\n"; } } }
void vtkStructuredGridFacelistFilter::Execute() { int i, j; vtkStructuredGrid *input = GetInput(); vtkPolyData *output = GetOutput(); vtkCellData *inCellData = input->GetCellData(); vtkCellData *outCellData = output->GetCellData(); int dims[3]; input->GetDimensions(dims); int nX = dims[0]; int nY = dims[1]; int nZ = dims[2]; int numOutCells = 0; if (nX > 1) numOutCells += 2*(nY-1)*(nZ-1); else numOutCells += (nY-1)*(nZ-1); if (nY > 1) numOutCells += 2*(nX-1)*(nZ-1); else numOutCells += (nX-1)*(nZ-1); if (nZ > 1) numOutCells += 2*(nX-1)*(nY-1); else numOutCells += (nX-1)*(nY-1); // // Copy over the points and the point data. // output->SetPoints(input->GetPoints()); output->GetPointData()->PassData(input->GetPointData()); // // Have the cell data allocate memory. // outCellData->CopyAllocate(inCellData); vtkCellArray *polys = vtkCellArray::New(); vtkIdTypeArray *list = vtkIdTypeArray::New(); list->SetNumberOfValues(numOutCells*(4+1)); vtkIdType *nl = list->GetPointer(0); // // Left face // int cellId = 0; for (i = 0 ; i < nY-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(0, i, j, nX, nY, nZ); *nl++ = PointIndex(0, i, j+1, nX, nY, nZ); *nl++ = PointIndex(0, i+1, j+1, nX, nY, nZ); *nl++ = PointIndex(0, i+1, j, nX, nY, nZ); int cId = CellIndex(0, i, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } // // Right face // if (nX > 1) { for (i = 0 ; i < nY-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(nX-1, i, j, nX, nY, nZ); *nl++ = PointIndex(nX-1, i+1, j, nX, nY, nZ); *nl++ = PointIndex(nX-1, i+1, j+1, nX, nY, nZ); *nl++ = PointIndex(nX-1, i, j+1, nX, nY, nZ); int cId = CellIndex(nX-2, i, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } } // // Bottom face // for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, 0, j, nX, nY, nZ); *nl++ = PointIndex(i+1, 0, j, nX, nY, nZ); *nl++ = PointIndex(i+1, 0, j+1, nX, nY, nZ); *nl++ = PointIndex(i, 0, j+1, nX, nY, nZ); int cId = CellIndex(i, 0, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } // // Top face // if (nY > 1) { for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, nY-1, j, nX, nY, nZ); *nl++ = PointIndex(i, nY-1, j+1, nX, nY, nZ); *nl++ = PointIndex(i+1, nY-1, j+1, nX, nY, nZ); *nl++ = PointIndex(i+1, nY-1, j, nX, nY, nZ); int cId = CellIndex(i, nY-2, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } } // // Back face // for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nY-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, j, 0, nX, nY, nZ); *nl++ = PointIndex(i, j+1, 0, nX, nY, nZ); *nl++ = PointIndex(i+1, j+1, 0, nX, nY, nZ); *nl++ = PointIndex(i+1, j, 0, nX, nY, nZ); int cId = CellIndex(i, j, 0, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } // // Front face // if (nZ > 1) { for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nY-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, j, nZ-1, nX, nY, nZ); *nl++ = PointIndex(i+1, j, nZ-1, nX, nY, nZ); *nl++ = PointIndex(i+1, j+1, nZ-1, nX, nY, nZ); *nl++ = PointIndex(i, j+1, nZ-1, nX, nY, nZ); int cId = CellIndex(i, j, nZ-2, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } } polys->SetCells(numOutCells, list); list->Delete(); outCellData->Squeeze(); output->SetPolys(polys); polys->Delete(); }
void SingularEdge :: FindPointsOnEdge (class Mesh & mesh) { (*testout) << "find points on edge" << endl; int j; points.SetSize(0); segms.SetSize(0); ARRAY<int> si1, si2; sol1->GetSurfaceIndices (si1); sol2->GetSurfaceIndices (si2); for (int i = 0; i < si1.Size(); i++) si1[i] = geom.GetSurfaceClassRepresentant(si1[i]); for (int i = 0; i < si2.Size(); i++) si2[i] = geom.GetSurfaceClassRepresentant(si2[i]); for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++) { INDEX_2 i2 (mesh[si].p1, mesh[si].p2); /* bool onedge = 1; for (j = 1; j <= 2; j++) { const Point<3> p = mesh[ PointIndex (i2.I(j)) ]; if (sol1->IsIn (p, 1e-3) && sol2->IsIn(p, 1e-3) && !sol1->IsStrictIn (p, 1e-3) && !sol2->IsStrictIn(p, 1e-3)) { ; } else onedge = 0; } */ if (domnr != -1 && domnr != mesh[si].domin && domnr != mesh[si].domout) continue; /* bool onedge = 1; for (int j = 0; j < 2; j++) { int surfi = (j == 0) ? mesh[si].surfnr1 : mesh[si].surfnr2; surfi = geom.GetSurfaceClassRepresentant(surfi); if (!si1.Contains(surfi) && !si2.Contains(surfi)) onedge = 0; } */ int surfi1 = geom.GetSurfaceClassRepresentant(mesh[si].surfnr1); int surfi2 = geom.GetSurfaceClassRepresentant(mesh[si].surfnr2); if (si1.Contains(surfi1) && si2.Contains(surfi2) || si1.Contains(surfi2) && si2.Contains(surfi1)) // if (onedge) { segms.Append (i2); // PrintMessage (5, "sing segment ", i2.I1(), " - ", i2.I2()); points.Append (mesh[ PointIndex (i2.I1())]); points.Append (mesh[ PointIndex (i2.I2())]); mesh[si].singedge_left = factor; mesh[si].singedge_right = factor; } } /* (*testout) << "Singular edge points:" << endl; for (int i = 0; i < points.Size(); i++) (*testout) << points[i] << endl; */ }
void NeighborAlgorithms::compute_k_nearest_neighbor(Data* data, distance_type d) { data->k_nearest_neighbors.clear(); data->distance_pA_pB.clear(); double(*distance)(Vector3D& p1, Vector3D& p2); //Wähle passende distance-Funktion aus if (d == euclid) distance = NeighborAlgorithms::compute_euclid_distance; else distance = NeighborAlgorithms::compute_euclid_distance; double tmp,tmp2; unsigned int tmp3; PointIndex tmpi, tmpi2; //Berechne distance zwischen allen Punkten for (unsigned int i = 0; i < data->points.size(); i++) { for (unsigned int j = 0; j < data->points.size(); j++) { //Sofern distance zwischen Punkten noch nicht berechnet, berechne if (data->distance_pA_pB[i][j] == 0) { tmp = data->distance_pA_pB[j][i]; //Prüfe ob Punktepaar schon berechnet wurde if (tmp != 0) { data->distance_pA_pB[i][j] = tmp; } else { //Berechne distance zwischen Punkten data->distance_pA_pB[i][j] = distance(data->points[i], data->points[j]); } //Speichere für alle Punkte ihre k-nearest neighbors in Form des Punktes und seines Index in der Punkteliste data->k_nearest_neighbors[i][j] = PointIndex(data->points[j], j); } } //std::cout << i+1 << " von " << data->points.size() << " Nachrbarschaften berechnet." << std::endl; } //Sortiere k-nearest neighbors dumm durch Sortieren mit Einfügen mit Hilfe der Liste von PointIndex Objekten for (unsigned int i = 0; i < data->points.size(); i++) { for (unsigned int j = 0; j < data->points.size(); j++) { tmp = data->distance_pA_pB[i][j]; tmpi = data->k_nearest_neighbors[i][j]; tmp3 = j; for (unsigned int l = j + 1; l < data->points.size(); l++) { if (data->distance_pA_pB[i][l] < tmp) { tmp = data->distance_pA_pB[i][l]; tmpi = data->k_nearest_neighbors[i][l]; tmp3 = l; } } if (tmp3 != j) { tmp2 = data->distance_pA_pB[i][j]; tmpi2 = data->k_nearest_neighbors[i][j]; data->distance_pA_pB[i][j] = tmp; data->k_nearest_neighbors[i][j] = tmpi; data->distance_pA_pB[i][tmp3] = tmp2; data->k_nearest_neighbors[i][tmp3] = tmpi2; } } //std::cout << i + 1 << " von " << data->points.size() << " Nachrbarschaften sortiert." << std::endl; } }
void ribi::foam::FacesFile::Test() noexcept { { static bool is_tested{false}; if (is_tested) return; is_tested = true; } const TestTimer test_timer(__func__,__FILE__,1.0); //Some initial data const Header header("some_name","some_location","some_object"); std::vector<FacesFileItem> items; for (int i=1; i!=4; ++i) { FacesFileItem item( std::vector<PointIndex>(i,PointIndex(i))); items.push_back(item); } //operator== { const FacesFile b(header,items); const FacesFile c(header,items); assert(header == header); assert(b == c); } //operator!= { const FacesFile b(header,items); const Header other_header("some_other_name","some_other_location","some_other_object"); assert(header != other_header); const FacesFile c(other_header,items); assert(b != c); } //operator!= { const FacesFile b(header,items); std::vector<FacesFileItem> other_items; for (int i=1; i!=3; ++i) { FacesFileItem item( std::vector<PointIndex>(i+1,PointIndex(i*i)) ); other_items.push_back(item); } const FacesFile c(header,other_items); assert(b != c); } //Stream conversion { const FacesFile b(header,items); std::stringstream s; s << b; FacesFile c; s >> c; if (b != c) { TRACE(b); TRACE(c); } assert(b == c); } //Read from testing file for (int test_index = 0; test_index!=5; ++test_index) { std::string filename_appendix; switch (test_index) { case 0: filename_appendix = "_1x1x1"; break; case 1: filename_appendix = "_1x1x2"; break; case 2: filename_appendix = "_1x2x2"; break; case 3: filename_appendix = "_2x2x2"; break; case 4: filename_appendix = "_3x4x5"; break; default: assert(!"Should never get here"); throw std::logic_error("foam::Files::CreateTestFiles: unknown test index"); } assert(!filename_appendix.empty()); const std::string filename_base { GetDefaultHeader().GetObject() }; const std::string filename = filename_base + filename_appendix; const std::string resources_path { ":/CppOpenFoam/files/" + filename }; { QFile f( resources_path.c_str() ); f.copy(filename.c_str()); } { if (!fileio::FileIo().IsRegularFile(filename)) { TRACE("ERROR"); TRACE(filename); } assert(fileio::FileIo().IsRegularFile(filename)); FacesFile b(filename); if (b.GetItems().empty()) { TRACE("ERROR"); } assert( (!b.GetItems().empty() || b.GetItems().empty()) && "If a mesh has no non-bhoundary cells, neighbour can be empty"); } } }
void midpoint_circle_push_pixel(int x, int y, int x_c, int y_c, vector<PointIndex>& result_out, int& c00, int& c01, int& c10, int& c11, int& c20, int& c21, int& c30, int& c31) { Point pt00 = Point(x_c - x, y_c - y); --c00; int index00 = c00 + 100000; Point pt01 = Point(x_c + x, y_c - y); ++c01; int index01 = c01 + 100000; Point pt10 = Point(x_c + y, y_c - x); --c10; int index10 = c10 + 200000; Point pt11 = Point(x_c + y, y_c + x); ++c11; int index11 = c11 + 200000; Point pt20 = Point(x_c - x, y_c + y); ++c20; int index20 = c20 + 300000; Point pt21 = Point(x_c + x, y_c + y); --c21; int index21 = c21 + 300000; Point pt30 = Point(x_c - y, y_c - x); ++c30; int index30 = c30 + 400000; Point pt31 = Point(x_c - y, y_c + x); --c31; int index31 = c31 + 400000; PointIndex pt_index00 = PointIndex(pt00, index00); PointIndex pt_index01 = PointIndex(pt01, index01); PointIndex pt_index10 = PointIndex(pt10, index10); PointIndex pt_index11 = PointIndex(pt11, index11); PointIndex pt_index20 = PointIndex(pt20, index20); PointIndex pt_index21 = PointIndex(pt21, index21); PointIndex pt_index30 = PointIndex(pt30, index30); PointIndex pt_index31 = PointIndex(pt31, index31); if(std::find(result_out.begin(), result_out.end(), pt_index00) == result_out.end()) result_out.push_back(pt_index00); if(std::find(result_out.begin(), result_out.end(), pt_index01) == result_out.end()) result_out.push_back(pt_index01); if(std::find(result_out.begin(), result_out.end(), pt_index10) == result_out.end()) result_out.push_back(pt_index10); if(std::find(result_out.begin(), result_out.end(), pt_index11) == result_out.end()) result_out.push_back(pt_index11); if(std::find(result_out.begin(), result_out.end(), pt_index20) == result_out.end()) result_out.push_back(pt_index20); if(std::find(result_out.begin(), result_out.end(), pt_index21) == result_out.end()) result_out.push_back(pt_index21); if(std::find(result_out.begin(), result_out.end(), pt_index30) == result_out.end()) result_out.push_back(pt_index30); if(std::find(result_out.begin(), result_out.end(), pt_index31) == result_out.end()) result_out.push_back(pt_index31); }
PointIndex operator-- (int) { int hi = i; i--; return PointIndex(hi); }
PointIndex operator++ (int) { int hi = i; i++; return PointIndex(hi); }