753 lines
20 KiB
C++
753 lines
20 KiB
C++
#include<iostream>
|
|
|
|
#include<iostream>
|
|
#include<fstream>
|
|
#include<string>
|
|
#include<sstream>
|
|
|
|
#include<vtkProperty.h>
|
|
#include<vtkActor.h>
|
|
#include<vtkDataSetMapper.h>
|
|
#include<vtkPoints.h>
|
|
#include<vtkCellData.h>
|
|
#include<vtkCellArray.h>
|
|
#include<vtkQuad.h>
|
|
#include<vtkLine.h>
|
|
#include<vtkHexahedron.h>
|
|
#include<vtkUnstructuredGrid.h>
|
|
#include<vtkUnstructuredGridWriter.h>
|
|
#include<vtkXMLUnstructuredGridWriter.h>
|
|
|
|
#include "gen2DGrid.h"
|
|
#include "readJson.h"
|
|
using namespace std;
|
|
|
|
gen2DGrid::gen2DGrid()
|
|
{
|
|
m_vtk_actor = vtkSmartPointer<vtkActor>::New();
|
|
m_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
|
m_grid_surface = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
|
|
|
//1 center 0 leftBottom
|
|
m_offset_type = 0;
|
|
m_length = 10;
|
|
m_width = 10;
|
|
m_height = 10;
|
|
m_offset_x = 0;
|
|
m_offset_y = 0;
|
|
m_offset_z = 0;
|
|
m_max_interval_x = 5;
|
|
m_max_interval_y = 5;
|
|
m_max_interval_z = 5;
|
|
|
|
m_color_x = 0.75;
|
|
m_color_y = 0.75;
|
|
m_color_z = 0.75;
|
|
m_opacity = 1.0;
|
|
m_line_width = 1.0;
|
|
m_write_xml_type = 1; //1 vtu 0 vtk
|
|
m_write_data_type = 1; //1 binary 0 asciii
|
|
|
|
vec_points.clear();
|
|
vec_elements.clear();
|
|
}
|
|
|
|
gen2DGrid::~gen2DGrid()
|
|
{
|
|
|
|
}
|
|
|
|
void gen2DGrid::genProcess()
|
|
{
|
|
vec_points.clear();
|
|
vec_elements.clear();
|
|
float origin_x = m_offset_x;
|
|
float origin_y = m_offset_y;
|
|
float origin_z = m_offset_z;
|
|
|
|
float length = m_length;
|
|
float width = m_width;
|
|
float height = m_height;
|
|
|
|
float max_interval_x = m_max_interval_x;
|
|
float max_interval_y = m_max_interval_y;
|
|
float max_interval_z = m_max_interval_z;
|
|
|
|
int max_num_x = floor(length/max_interval_x) + 1;
|
|
int max_num_y = floor(width/max_interval_y) + 1;
|
|
int max_num_z = floor(height/max_interval_z) + 1;
|
|
|
|
float point_min_x = 0.0;
|
|
float point_min_y = 0.0;
|
|
float point_min_z = 0.0;
|
|
float point_max_x = 0.0;
|
|
float point_max_y = 0.0;
|
|
float point_max_z = 0.0;
|
|
|
|
if(ceil(length/max_interval_x) == floor(length/max_interval_x))
|
|
max_num_x = floor(length/max_interval_x);
|
|
|
|
if(ceil(width/max_interval_y) == floor(width/max_interval_y))
|
|
max_num_y = floor(width/max_interval_y);
|
|
|
|
if(ceil(height/max_interval_z) == floor(height/max_interval_z))
|
|
max_num_z = floor(height/max_interval_z);
|
|
|
|
int type = m_offset_type;
|
|
float use_interval_x = length / max_num_x;
|
|
float use_interval_y = width / max_num_y;
|
|
//float use_interval_z = height / max_num_z;
|
|
|
|
int use_number_x = max_num_x + 1;
|
|
int use_number_y = max_num_y + 1;
|
|
int use_number_z = max_num_z + 1;
|
|
|
|
if(0==type)
|
|
{
|
|
point_min_x = origin_x + 0;
|
|
point_min_y = origin_y + 0;
|
|
point_min_z = origin_y + 0;
|
|
point_max_x = origin_x + length;
|
|
point_max_y = origin_y + width;
|
|
point_max_z = origin_z + height;
|
|
}
|
|
else if(1==type)
|
|
{
|
|
point_min_x = origin_x - length/2.0;
|
|
point_min_y = origin_y - width/2.0;
|
|
point_min_z = origin_y - height/2.0;
|
|
point_max_x = origin_x + length/2.0;
|
|
point_max_y = origin_y + width/2.0;
|
|
point_max_z = origin_z + height/2.0;
|
|
}
|
|
|
|
|
|
float temp_x = 0.0;
|
|
float temp_y = 0.0;
|
|
//float temp_z = 0.0;
|
|
|
|
vec_set_point.clear();
|
|
std::set<int> set_point0;
|
|
std::set<int> set_point1;
|
|
std::set<int> set_point2;
|
|
std::set<int> set_point3;
|
|
|
|
m_faceToPoint.resize(4+1);
|
|
m_faceToCell.resize(4+1);
|
|
|
|
for (int j=0;j<use_number_y;j++)
|
|
{
|
|
temp_y = point_min_y + use_interval_y*j;
|
|
if (j==use_number_y-1)
|
|
{
|
|
temp_y = point_max_y;
|
|
}
|
|
|
|
for (int i=0;i<use_number_x;i++)
|
|
{
|
|
temp_x = point_min_x + use_interval_x*i;
|
|
if (i==use_number_x-1)
|
|
{
|
|
temp_x = point_max_x;
|
|
}
|
|
vec_points.push_back(temp_x);
|
|
vec_points.push_back(temp_y);
|
|
vec_points.push_back(0);
|
|
|
|
if(j==0)
|
|
{
|
|
set_point0.insert(j*use_number_x+i);
|
|
m_faceToPoint[0+1].insert(j*use_number_x+i+1);
|
|
}
|
|
|
|
if(j==use_number_y-1)
|
|
{
|
|
|
|
set_point1.insert(j*use_number_x+i);
|
|
m_faceToPoint[1+1].insert(j*use_number_x+i+1);
|
|
}
|
|
|
|
if(i==0)
|
|
{
|
|
|
|
set_point2.insert(j*use_number_x+i);
|
|
m_faceToPoint[2+1].insert(j*use_number_x+i+1);
|
|
}
|
|
|
|
if(i==use_number_x-1)
|
|
{
|
|
// std::cout<<j*use_number_x+i<<std::endl;
|
|
set_point3.insert(j*use_number_x+i);
|
|
m_faceToPoint[3+1].insert(j*use_number_x+i+1);
|
|
}
|
|
}
|
|
}
|
|
vec_set_point.push_back(set_point0);
|
|
vec_set_point.push_back(set_point1);
|
|
vec_set_point.push_back(set_point2);
|
|
vec_set_point.push_back(set_point3);
|
|
|
|
vec_set_cell.clear();
|
|
std::set<int> set_cell0;
|
|
std::set<int> set_cell1;
|
|
std::set<int> set_cell2;
|
|
std::set<int> set_cell3;
|
|
|
|
for (int j=0;j<use_number_y-1;j++)
|
|
{
|
|
for (int i=0;i<use_number_x-1;i++)
|
|
{
|
|
vec_elements.push_back(i+j*use_number_x);
|
|
vec_elements.push_back((i+1)+j*use_number_x);
|
|
vec_elements.push_back((i+1)+(j+1)*use_number_x);
|
|
vec_elements.push_back(i+(j+1)*use_number_x);
|
|
|
|
if(j==0)
|
|
{
|
|
//std::cout<<j*(use_number_x-1)+i<<std::endl;
|
|
set_cell0.insert(j*(use_number_x-1)+i);
|
|
}
|
|
|
|
if(j==use_number_y-2)
|
|
{
|
|
|
|
set_cell1.insert(j*(use_number_x-1)+i);
|
|
}
|
|
|
|
if(i==0)
|
|
{
|
|
//std::cout<<j*(use_number_x-1)+i<<std::endl;
|
|
set_cell2.insert(j*(use_number_x-1)+i);
|
|
}
|
|
|
|
if(i==use_number_y-2)
|
|
{
|
|
//std::cout<<j*(use_number_x-1)+i<<std::endl;
|
|
set_cell3.insert(j*(use_number_x-1)+i);
|
|
}
|
|
}
|
|
}
|
|
|
|
vec_set_cell.push_back(set_cell0);
|
|
vec_set_cell.push_back(set_cell1);
|
|
vec_set_cell.push_back(set_cell2);
|
|
vec_set_cell.push_back(set_cell3);
|
|
|
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
|
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
|
|
float point[3];
|
|
for (auto iter = vec_points.begin(); iter != vec_points.end();)
|
|
{
|
|
//std::cout<<*iter++;
|
|
//std::cout<<*iter++;
|
|
//std::cout<<*iter++<<endl;
|
|
point[0]=*iter++;
|
|
point[1]=*iter++;
|
|
point[2]=*iter++;
|
|
points->InsertNextPoint(point);
|
|
}
|
|
|
|
m_grid->SetPoints(points);
|
|
|
|
float quad[4];
|
|
for (auto iter = vec_elements.begin(); iter != vec_elements.end();)
|
|
{
|
|
vtkSmartPointer<vtkQuad> quadpoly = vtkSmartPointer<vtkQuad>::New();
|
|
quad[0]=*iter++;
|
|
quad[1]=*iter++;
|
|
quad[2]=*iter++;
|
|
quad[3]=*iter++;
|
|
quadpoly->GetPointIds()->SetId(0, quad[0]);
|
|
quadpoly->GetPointIds()->SetId(1, quad[1]);
|
|
quadpoly->GetPointIds()->SetId(2, quad[2]);
|
|
quadpoly->GetPointIds()->SetId(3, quad[3]);
|
|
m_grid->InsertNextCell(quadpoly->GetCellType(), quadpoly->GetPointIds());
|
|
}
|
|
|
|
genSurfaceGrid();
|
|
|
|
//vtkSmartPointer<vtkDataSetMapper>mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
|
//mapper->SetInputData(m_grid);
|
|
|
|
//m_vtk_actor->SetMapper(mapper);
|
|
//m_vtk_actor->GetProperty()->SetColor(m_color_x, m_color_y, m_color_z);
|
|
//m_vtk_actor->GetProperty()->SetOpacity(m_opacity);
|
|
//m_vtk_actor->GetProperty()->SetRepresentationToWireframe();
|
|
}
|
|
|
|
void gen2DGrid::genSurfaceGrid()
|
|
{
|
|
|
|
vtkSmartPointer<vtkCellArray> cells_temp;
|
|
vtkSmartPointer<vtkPoints> points_temp = vtkSmartPointer<vtkPoints>::New();
|
|
//vtkSmartPointer<vtkUnstructuredGrid> poly_temp = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
|
//m_grid_surface
|
|
m_grid_surface->SetPoints(m_grid->GetPoints());
|
|
vtkSmartPointer<vtkLine> quadpoly = vtkSmartPointer<vtkLine>::New();
|
|
|
|
int quad[2];
|
|
int count_temp = 0;
|
|
for (int i_surface_id=0;i_surface_id<4;i_surface_id++)
|
|
{
|
|
std::cout<<vec_set_cell[i_surface_id].size()<<std::endl;
|
|
if(i_surface_id==0)
|
|
{
|
|
quad[0]=0;
|
|
quad[1]=1;
|
|
}
|
|
else if(i_surface_id==1)
|
|
{
|
|
quad[0]=2;
|
|
quad[1]=3;
|
|
}
|
|
else if(i_surface_id==2)
|
|
{
|
|
quad[0]=3;
|
|
quad[1]=0;
|
|
}
|
|
else if(i_surface_id==3)
|
|
{
|
|
quad[0]=1;
|
|
quad[1]=2;
|
|
}
|
|
|
|
for (std::set<int>::iterator it = vec_set_cell[i_surface_id].begin(); it != vec_set_cell[i_surface_id].end(); ++it)
|
|
{
|
|
m_faceToCell[i_surface_id+1].push_back(count_temp+1);
|
|
m_cellIdToGridCellId[count_temp] = *it;
|
|
count_temp++;
|
|
|
|
vtkIdList* pointIds2 = vtkIdList::New();
|
|
m_grid->GetCellPoints(*it, pointIds2);
|
|
|
|
quadpoly->GetPointIds()->SetId(0, pointIds2->GetId(quad[0]));
|
|
quadpoly->GetPointIds()->SetId(1, pointIds2->GetId(quad[1]));
|
|
m_grid_surface->InsertNextCell(quadpoly-> GetCellType(), quadpoly ->GetPointIds());
|
|
}
|
|
}
|
|
|
|
//vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
|
|
//writer->SetFileName("ceshi0826.vtu");
|
|
//writer->SetDataType(m_write_data_type);
|
|
//writer->SetDataModeToAscii(); //0
|
|
//writer->SetDataModeToBinary(); //1
|
|
//std::cout<<writer->GetDataMode()<<std::endl;
|
|
//writer->SetInputData(m_grid_surface);
|
|
//writer->Write();
|
|
|
|
vtkSmartPointer<vtkDataSetMapper>mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
|
mapper->SetInputData(m_grid_surface);
|
|
mapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(5.0,5.0);
|
|
|
|
m_vtk_actor->SetMapper(mapper);
|
|
m_vtk_actor->GetProperty()->SetColor(m_color_x, m_color_y, m_color_z);
|
|
|
|
m_vtk_actor->GetProperty()->SetOpacity(m_opacity);
|
|
//m_vtk_actor->GetProperty()->SetRepresentationToWireframe();
|
|
m_vtk_actor->GetProperty()->SetRepresentationToSurface();
|
|
//m_vtk_actor->GetProperty()->SetEdgeVisibility(true);
|
|
|
|
//m_vtk_actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
|
|
//m_vtk_actor->PickableOff();
|
|
//m_vtk_actor->DragableOff();
|
|
|
|
}
|
|
|
|
|
|
void gen2DGrid::readGridJsonFile(string json_name)
|
|
{
|
|
CasRockGrid* struct_grid = new CasRockGrid;
|
|
readJson *use_readJson = new readJson;
|
|
use_readJson->readGridJson(json_name,struct_grid);
|
|
|
|
m_offset_type = struct_grid->offset_type;
|
|
m_length = struct_grid->length;
|
|
m_width = struct_grid->width;
|
|
m_height = 0;
|
|
m_offset_x = struct_grid->offset_x;
|
|
m_offset_y = struct_grid->offset_y;
|
|
m_offset_z = 0;
|
|
|
|
m_max_interval_x = struct_grid->max_interval_x;
|
|
m_max_interval_y = struct_grid->max_interval_y;
|
|
m_max_interval_z = 0;
|
|
|
|
delete struct_grid;
|
|
delete use_readJson;
|
|
struct_grid = NULL;
|
|
use_readJson = NULL;
|
|
}
|
|
|
|
void gen2DGrid::readModelJsonFile(string json_name)
|
|
{
|
|
CasRockModel* struct_model = new CasRockModel;
|
|
readJson *use_readJson = new readJson;
|
|
use_readJson->readModelJson(json_name,struct_model);
|
|
|
|
m_offset_type = struct_model->offset_type;
|
|
m_length = struct_model->length;
|
|
m_width = struct_model->width;
|
|
m_height = 0;
|
|
m_offset_x = struct_model->offset_x;
|
|
m_offset_y = struct_model->offset_y;
|
|
m_offset_z = 0;
|
|
|
|
delete struct_model;
|
|
delete use_readJson;
|
|
struct_model = NULL;
|
|
use_readJson = NULL;
|
|
}
|
|
|
|
void gen2DGrid::writeGridJsonFile(string json_name)
|
|
{
|
|
CasRockGrid* struct_grid = new CasRockGrid;
|
|
readJson *use_readJson = new readJson;
|
|
struct_grid->geo_type = 0;
|
|
struct_grid->offset_type = m_offset_type;
|
|
struct_grid->length = m_length;
|
|
struct_grid->width = m_width;
|
|
struct_grid->height = 0;
|
|
struct_grid->offset_x = m_offset_x;
|
|
struct_grid->offset_y = m_offset_y;
|
|
struct_grid->offset_z = 0;
|
|
|
|
struct_grid->max_interval_x = m_max_interval_x;
|
|
struct_grid->max_interval_y = m_max_interval_y;
|
|
struct_grid->max_interval_z = -1;
|
|
|
|
use_readJson->writeGridJson(json_name,struct_grid);
|
|
delete struct_grid;
|
|
delete use_readJson;
|
|
struct_grid = NULL;
|
|
use_readJson = NULL;
|
|
}
|
|
|
|
void gen2DGrid::setGridParams(CasRockGrid* struct_grid)
|
|
{
|
|
m_offset_type = struct_grid->offset_type;
|
|
m_length = struct_grid->length;
|
|
m_width = struct_grid->width;
|
|
m_height = 0;
|
|
m_offset_x = struct_grid->offset_x;
|
|
m_offset_y = struct_grid->offset_y;
|
|
m_offset_z = 0;
|
|
m_max_interval_x = struct_grid->max_interval_x;
|
|
m_max_interval_y = struct_grid->max_interval_y;
|
|
m_max_interval_z = -1;
|
|
}
|
|
|
|
void gen2DGrid::setModelParams(CasRockModel* struct_model)
|
|
{
|
|
m_offset_type = struct_model->offset_type;
|
|
m_length = struct_model->length;
|
|
m_width = struct_model->width;
|
|
m_height = 0;
|
|
m_offset_x = struct_model->offset_x;
|
|
m_offset_y = struct_model->offset_y;
|
|
m_offset_z = 0;
|
|
}
|
|
|
|
void gen2DGrid::getGridParams(CasRockGrid *struct_grid)
|
|
{
|
|
struct_grid->geo_type = 0;
|
|
struct_grid->offset_type = m_offset_type;
|
|
struct_grid->length = m_length;
|
|
struct_grid->width = m_width;
|
|
struct_grid->height = 0;
|
|
struct_grid->offset_x = m_offset_x;
|
|
struct_grid->offset_y = m_offset_y;
|
|
struct_grid->offset_z = 0;
|
|
struct_grid->max_interval_x = m_max_interval_x;
|
|
struct_grid->max_interval_y = m_max_interval_y;
|
|
struct_grid->max_interval_z = -1;
|
|
}
|
|
|
|
vtkSmartPointer<vtkActor> gen2DGrid::getActor()
|
|
{
|
|
return m_vtk_actor;
|
|
}
|
|
|
|
void gen2DGrid::setOffsetType(int offset_type)
|
|
{
|
|
m_offset_type = offset_type;
|
|
}
|
|
|
|
void gen2DGrid::setOffsetTypeToCenter()
|
|
{
|
|
m_offset_type = 1;
|
|
}
|
|
|
|
void gen2DGrid::setOffsetTypeToLeftBottom()
|
|
{
|
|
m_offset_type = 0;
|
|
}
|
|
|
|
void gen2DGrid::setOffsetX(float offset_x)
|
|
{
|
|
m_offset_x = offset_x;
|
|
}
|
|
|
|
void gen2DGrid::setOffsetY(float offset_y)
|
|
{
|
|
m_offset_y = offset_y;
|
|
}
|
|
|
|
void gen2DGrid::setOffsetZ(float offset_z)
|
|
{
|
|
m_offset_z = 0;
|
|
}
|
|
|
|
void gen2DGrid::setMaxInterval(float max_interval)
|
|
{
|
|
m_max_interval_x = max_interval;
|
|
m_max_interval_y = max_interval;
|
|
m_max_interval_z = -1;
|
|
}
|
|
|
|
void gen2DGrid::setMaxIntervalX(float max_interval_x)
|
|
{
|
|
m_max_interval_x = max_interval_x;
|
|
}
|
|
|
|
void gen2DGrid::setMaxIntervalY(float max_interval_y)
|
|
{
|
|
m_max_interval_y = max_interval_y;
|
|
}
|
|
|
|
void gen2DGrid::setMaxIntervalZ(float max_interval_z)
|
|
{
|
|
m_max_interval_z = -1;
|
|
}
|
|
|
|
void gen2DGrid::setLength(float length)
|
|
{
|
|
m_length = length;
|
|
}
|
|
|
|
void gen2DGrid::setWidth(float width)
|
|
{
|
|
m_width = width;
|
|
}
|
|
|
|
void gen2DGrid::setHeight(float height)
|
|
{
|
|
m_height = 0;
|
|
}
|
|
|
|
void gen2DGrid::writeFile(string file_name)
|
|
{
|
|
if(m_write_xml_type ==0)
|
|
{
|
|
writeVtkFile(file_name);
|
|
}
|
|
else if(m_write_xml_type ==1)
|
|
{
|
|
writeVtuFile(file_name);
|
|
}
|
|
}
|
|
|
|
void gen2DGrid::setWriteXmlMode(int write_xml_type)
|
|
{
|
|
m_write_xml_type = write_xml_type;
|
|
}
|
|
|
|
void gen2DGrid::setWriteDataMode(int write_data_type)
|
|
{
|
|
m_write_data_type = write_data_type;
|
|
}
|
|
|
|
void gen2DGrid::setWriteDataModeToAscii()
|
|
{
|
|
m_write_data_type = 0;
|
|
}
|
|
|
|
void gen2DGrid::setWriteDataModeToBinary()
|
|
{
|
|
m_write_data_type = 1;
|
|
}
|
|
|
|
void gen2DGrid::setWriteXmlModeToVtu()
|
|
{
|
|
m_write_xml_type = 1;
|
|
}
|
|
|
|
void gen2DGrid::setWriteXmlModeToVtk()
|
|
{
|
|
m_write_xml_type = 0;
|
|
}
|
|
|
|
void gen2DGrid::writeVtkFile(string vtk_file_name)
|
|
{
|
|
vtkSmartPointer<vtkUnstructuredGridWriter> writer = vtkSmartPointer<vtkUnstructuredGridWriter>::New();
|
|
//writer->SetFileTypeToASCII(); //1
|
|
//writer->SetFileTypeToBinary(); //2
|
|
writer->SetFileType(m_write_data_type+1);
|
|
//std::cout<<writer->GetFileType()<<std::endl;
|
|
writer->SetFileName(vtk_file_name.c_str());
|
|
writer->SetInputData(m_grid);
|
|
writer->Write();
|
|
}
|
|
|
|
void gen2DGrid::writeVtuFile(string vtu_file_name)
|
|
{
|
|
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
|
|
writer->SetFileName(vtu_file_name.c_str());
|
|
//writer->SetDataType(m_write_data_type);
|
|
writer->SetDataModeToAscii(); //0
|
|
//writer->SetDataModeToBinary(); //1
|
|
//std::cout<<writer->GetDataMode()<<std::endl;
|
|
writer->SetInputData(m_grid);
|
|
writer->Write();
|
|
}
|
|
|
|
void gen2DGrid::writeGridFile(string nodes_file_name,string elements_file_name)
|
|
{
|
|
writeNodesFile(nodes_file_name);
|
|
writeElementsFile(elements_file_name);
|
|
}
|
|
|
|
void gen2DGrid::writeNodesFile(string nodes_file_name)
|
|
{
|
|
fstream os_coordinate;
|
|
os_coordinate.open(nodes_file_name.c_str(), ios::out);
|
|
ostringstream ostr_nodes;
|
|
os_coordinate << " " << to_string(vec_points.size()/3) << endl;
|
|
os_coordinate << endl;
|
|
float point[3];
|
|
int count = 0;
|
|
for (auto iter = vec_points.begin(); iter != vec_points.end();)
|
|
{
|
|
point[0]=*iter++;
|
|
point[1]=*iter++;
|
|
point[2]=*iter++;
|
|
ostr_nodes<<" ";
|
|
ostr_nodes<<count + 1<<" ";
|
|
ostr_nodes<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(8)<<point[0]<<" ";
|
|
ostr_nodes<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(8)<<point[1]<<" ";;
|
|
ostr_nodes<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(8)<<point[2]<<" ";;
|
|
os_coordinate << ostr_nodes.str() << endl;
|
|
ostr_nodes.str("");
|
|
count=count+1;
|
|
}
|
|
os_coordinate.close();
|
|
}
|
|
|
|
void gen2DGrid::writeElementsFile(string elements_file_name)
|
|
{
|
|
fstream os_elements;
|
|
os_elements.open(elements_file_name.c_str(), ios::out);
|
|
ostringstream ostr_elements;
|
|
|
|
int quad[4];
|
|
os_elements << " " << to_string(vec_elements.size()/4) << " " << endl;
|
|
os_elements << endl;
|
|
|
|
int count = 0;
|
|
for (auto iter = vec_elements.begin(); iter != vec_elements.end();)
|
|
{
|
|
quad[0]=*iter++;
|
|
quad[1]=*iter++;
|
|
quad[2]=*iter++;
|
|
quad[3]=*iter++;
|
|
ostr_elements<<count + 1<<" "<<1<<" ";
|
|
ostr_elements<<quad[0]+1<<" ";
|
|
ostr_elements<<quad[1]+1<<" ";
|
|
ostr_elements<<quad[2]+1<<" ";
|
|
ostr_elements<<quad[3]+1<<" ";
|
|
os_elements << ostr_elements.str() << endl;
|
|
ostr_elements.str("");
|
|
count =count +1;
|
|
}
|
|
os_elements.close();
|
|
}
|
|
|
|
void gen2DGrid::setColor(float color_x, float color_y, float color_z)
|
|
{
|
|
m_color_x = color_x;
|
|
m_color_y = color_y;
|
|
m_color_z = color_z;
|
|
}
|
|
|
|
void gen2DGrid::setOpacity(float opacity)
|
|
{
|
|
m_opacity = opacity;
|
|
}
|
|
|
|
void gen2DGrid::setLineWidth(float line_width)
|
|
{
|
|
m_line_width = line_width;
|
|
}
|
|
|
|
void gen2DGrid::update()
|
|
{
|
|
m_vtk_actor->GetProperty()->SetColor(m_color_x, m_color_y, m_color_z);
|
|
m_vtk_actor->GetProperty()->SetOpacity(m_opacity);
|
|
}
|
|
|
|
void gen2DGrid::updateColor(float color_x, float color_y, float color_z)
|
|
{
|
|
m_vtk_actor->GetProperty()->SetColor(color_x, color_y, color_z);
|
|
}
|
|
|
|
void gen2DGrid::updateOpacity(float opacity)
|
|
{
|
|
m_vtk_actor->GetProperty()->SetOpacity(opacity);
|
|
}
|
|
|
|
void gen2DGrid::updateLineWidth(float line_width)
|
|
{
|
|
m_vtk_actor->GetProperty()->SetLineWidth(line_width);
|
|
}
|
|
|
|
vector<set<int>>& gen2DGrid::getPointSetWithSurface()
|
|
{
|
|
return vec_set_point;
|
|
}
|
|
|
|
vector<set<int>>& gen2DGrid::getCellSetWithSurface()
|
|
{
|
|
return vec_set_cell;
|
|
}
|
|
|
|
vtkSmartPointer<vtkUnstructuredGrid> gen2DGrid::getStructure()
|
|
{
|
|
return m_grid_surface;
|
|
}
|
|
|
|
vtkSmartPointer<vtkUnstructuredGrid> gen2DGrid::getStructureOrigin()
|
|
{
|
|
return m_grid;
|
|
}
|
|
|
|
QVector<QSet<int>> gen2DGrid::getFaceToPoint()
|
|
{
|
|
return m_faceToPoint;
|
|
}
|
|
|
|
QVector<QVector<int>> gen2DGrid::getFaceToCell()
|
|
{
|
|
return m_faceToCell;
|
|
}
|
|
|
|
QMap<int,int> gen2DGrid::getCellIdToGridIdMap()
|
|
{
|
|
return m_cellIdToGridCellId;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|