1 #include <vtkTransform.h> 3 #include <vtkProperty2D.h> 4 #include <vtkTextProperty.h> 5 #include <vtkCommand.h> 6 #include <vtkDataSetSurfaceFilter.h> 7 #include <vtkTransformFilter.h> 8 #include <vtkOutlineFilter.h> 9 #include <vtkCubeAxesActor2D.h> 10 #include <vtkMapper.h> 11 #include <vtkMapper2D.h> 12 #include <vtkContextScene.h> 51 planecutX= vtkSmartPointer<vtkCutter>::New();
52 planecutY= vtkSmartPointer<vtkCutter>::New();
53 planecutZ= vtkSmartPointer<vtkCutter>::New();
55 arrow2d = vtkSmartPointer<vtkGlyphSource2D>::New();
58 arrow3ds= vtkSmartPointer<vtkArrowSource>::New();
64 arrow3dt=vtkSmartPointer<vtkTransform>::New();
65 arrow3d=vtkSmartPointer<vtkTransformPolyDataFilter>::New();
76 planeX= vtkSmartPointer<vtkPlane>::New();
78 planeY= vtkSmartPointer<vtkPlane>::New();
80 planeZ= vtkSmartPointer<vtkPlane>::New();
96 auto data=vtkDataSet::SafeDownCast(
data_producer->GetOutputDataObject(0));
98 auto values=vtkDoubleArray::SafeDownCast(data->GetPointData()->GetAbstractArray(
dataname.c_str()));
108 values->GetRange(vrange,-1);
109 state.data_vmin=vrange[0];
110 state.data_vmax=vrange[1];
148 auto cr=vtkDoubleArray::SafeDownCast(vtkfig_data.
GetVTKDataSet()->GetCellData()->GetAbstractArray(
"cellregions"));
153 cell_lut->SetTableRange(range[0],range[1]);
157 cbar->SetNumberOfLabels((
int)(range[1]-range[0]+1));
166 auto bcr=vtkDoubleArray::SafeDownCast(boundary_data->GetCellData()->GetAbstractArray(
"boundarycellregions"));
170 bcr->GetRange(range);
171 bface_lut->SetTableRange(range[0],range[1]);
175 bcbar->SetNumberOfLabels((
int)(range[1]-range[0]+1));
206 communicator->SendInt(rgbtab.size());
207 communicator->SendDoubleBuffer((
double*)rgbtab.data(),rgbtab.size()*
sizeof(
RGBPoint)/
sizeof(
double));
213 communicator->ReceiveInt(tabsize);
214 rgbtab.resize(tabsize);
215 communicator->ReceiveDoubleBuffer((
double*)rgbtab.data(),rgbtab.size()*
sizeof(
RGBPoint)/
sizeof(
double));
234 int i=planecut->GetNumberOfContours();
238 RTMessage(
"plane_" + plane +
"[" + std::to_string(i-1) +
"]=" + std::to_string(planepos));
243 RTMessage(
"[Return] for plane_"+plane+
"[0]="+std::to_string(planepos));
256 RTMessage(
"isolevel["+ std::to_string(i-1)+
"]="+std::to_string(isolevel));
260 RTMessage(
"[Return] for isolevel[0]="+std::to_string(0.5*(
state.real_vmin+
state.real_vmax)));
268 RTMessage(
"arrow_scale="+std::to_string(
state.quiver_arrowscale_user));
273 const std::string plane,
275 const std::string key,
277 vtkSmartPointer<vtkCutter> planecut)
280 if (!edit && key==plane)
287 if (edit && key==
"Return")
290 int i=planecut->GetNumberOfContours();
292 planepos=planecut->GetValue(i-1);
295 planecut->SetValue(i,planepos);
300 if (edit&& key==
"Delete")
302 int i=planecut->GetNumberOfContours();
304 planecut->SetNumberOfContours(i-1);
310 if (edit&& key==
"Escape")
321 if (!edit && key==
"l")
324 state.isolevels_locked=
true;
329 if (edit && key==
"Return")
336 isolevel=0.5*(
state.real_vmin+
state.real_vmax);
344 if (edit&& key==
"Delete")
354 if (edit&& key==
"Escape")
366 if (!edit && key==
"a")
373 if (edit&& key==
"Escape")
386 if (key==
"I" &&
state.spacedim==3)
389 state.show_isosurfaces=!
state.show_isosurfaces;
397 if (key==
"S" &&
state.spacedim==2)
408 if (key==
"E" &&
state.spacedim==2)
420 int vis=
axes->GetVisibility();
422 axes->SetVisibility(vis);
433 int vis=
splot->GetVisibility();
435 splot->SetVisibility(vis);
446 state.isolevels_locked=
false;
450 state.isolevels_locked=
true;
458 &&(key==
"x"|| key==
"y"|| key==
"z"|| key==
"l" || key==
"a")
477 vtkSmartPointer<vtkCutter> planecut )
481 int i=planecut->GetNumberOfContours()-1;
484 double planepos=planecut->GetValue(i)+
trans_center[idim];
490 planecut->Modified();
505 isolevel+=(0.01)*((double)dx)*(
state.real_vmax-
state.real_vmin);
506 isolevel=std::min(isolevel,
state.real_vmax);
507 isolevel=std::max(isolevel,
state.real_vmin);
522 double ascale=
state.quiver_arrowscale_user;
523 ascale*=pow(10.0,((
double)dy)/100.0);
524 ascale=std::min(ascale,1.0e20);
525 ascale=std::max(ascale,1.0e-20);
526 state.quiver_arrowscale_user=ascale;
530 arrow3dt->Scale(scalefac,scalefac,scalefac);
539 if (
state.spacedim==3)
543 for (
int i=0;i<n;i++)
562 state.contour_rgbtab_size=tabsize;
563 state.contour_rgbtab_modified=
true;
571 auto data=vtkDataSet::SafeDownCast(
data_producer->GetOutputDataObject(0));
594 throw std::runtime_error(
"Specify either view volume or dataset for figure\n");
597 transform = vtkSmartPointer<vtkTransform>::New();
600 double ysize=data_bounds[3]-data_bounds[2];
601 double zsize=data_bounds[5]-data_bounds[4];
602 if (
state.spacedim==2) zsize=0;
603 double xysize=std::max(xsize,ysize);
604 double xyzsize=std::max(xysize,zsize);
611 if (
state.keep_aspect)
614 transform->Translate(0,0.5*(xsize-ysize)/xyzsize,0);
616 transform->Translate(0.5*(ysize-xsize)/xyzsize,0,0);
618 transform->Scale(1.0/xyzsize, 1.0/xyzsize,1.0/xyzsize);
622 if (
state.aspect>1.0)
634 transform->Translate(-data_bounds[0],-data_bounds[2],-data_bounds[4]);
636 double p0[3]={data_bounds[0],data_bounds[2],data_bounds[4]};
637 double p1[3]={data_bounds[1],data_bounds[3],data_bounds[5]};
638 double tp0[3],tp1[3];
669 else if (
state.accumulate_range)
685 arrow3dt->Scale(scalefac,scalefac,scalefac);
690 double lut_min=
state.real_vmin;
691 double lut_max=
state.real_vmax;
718 if (!
state.isolevels_locked)
733 annot= vtkSmartPointer<vtkCornerAnnotation>::New();
734 auto textprop=
annot->GetTextProperty();
735 annot->SetMinimumFontSize(8);
736 annot->SetMaximumFontSize(20);
737 textprop->ItalicOff();
739 textprop->SetFontSize(8);
740 textprop->SetFontFamilyToCourier();
741 textprop->SetColor(0,0,0);
749 annot->SetText(4,
"");
750 annot->SetText(3,
"[ ]");
758 annot->SetText(3,
"[X]");
766 annot->SetText(3,
"[ ]");
773 annot->SetText(4,msg.c_str());
784 for (
auto actor:
actors) {
auto m=actor->GetMapper();
if (m) m->Update();}
785 for (
auto actor:
ctxactors) {
auto m=actor->GetScene();
if (m) m->SetDirty(
true);}
786 for (
auto actor:
actors2d){
auto m=actor->GetMapper();
if (m) m->Update();}
792 auto data=vtkDataSet::SafeDownCast(
data_producer->GetOutputDataObject(0));
796 communicator->SendCharBuffer((
char*)&
state,
sizeof(
state));
798 communicator->Send(data,1,1);
810 communicator->ReceiveCharBuffer((
char*)&
state,
sizeof(
state));
811 communicator->ReceiveString(
dataname);
813 vtkSmartPointer<vtkDataSet> data;
815 data=vtkSmartPointer<vtkRectilinearGrid>::New();
817 data=vtkSmartPointer<vtkUnstructuredGrid>::New();
818 communicator->Receive(data,1,1);
828 template <
class DATA>
833 auto geometry=vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
834 geometry->SetInputConnection(
data_producer->GetOutputPort());
836 auto transgeometry=vtkSmartPointer<vtkTransformFilter>::New();
837 transgeometry->SetInputConnection(geometry->GetOutputPort());
842 if (
state.show_domain_boundary &&
state.spacedim==3)
844 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
845 mapper->SetInputConnection(transgeometry->GetOutputPort());
846 splot=vtkSmartPointer<vtkActor>::New();
847 if (
state.spacedim==3)
849 splot->GetProperty()->SetOpacity(
state.domain_opacity);
850 splot->GetProperty()->SetColor(
state.domain_surface_color);
854 splot->GetProperty()->SetOpacity(1.0);
855 splot->GetProperty()->SetColor(0,0,0);
858 splot->SetMapper(mapper);
863 if (
state.show_domain_box&&
state.spacedim==3)
866 vtkSmartPointer<vtkOutlineFilter>outlinefilter = vtkSmartPointer<vtkOutlineFilter>::New();
867 outlinefilter->SetInputConnection(transgeometry->GetOutputPort());
868 vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
869 outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());
870 outline = vtkSmartPointer<vtkActor>::New();
871 outline->SetMapper(outlineMapper);
872 outline->GetProperty()->SetColor(0, 0, 0);
877 if (
state.show_domain_axes)
879 axes=vtkSmartPointer<vtkCubeAxesActor2D>::New();
880 double unscaled_data_bounds[6];
881 unscaled_data_bounds[0]=
data_bounds[0]/this->
state.coordinate_scale_factor_xyz[0];
882 unscaled_data_bounds[1]=
data_bounds[1]/this->
state.coordinate_scale_factor_xyz[0];
883 unscaled_data_bounds[2]=
data_bounds[2]/this->
state.coordinate_scale_factor_xyz[1];
884 unscaled_data_bounds[3]=
data_bounds[3]/this->
state.coordinate_scale_factor_xyz[1];
885 unscaled_data_bounds[4]=
data_bounds[4]/this->
state.coordinate_scale_factor_xyz[2];
886 unscaled_data_bounds[5]=
data_bounds[5]/this->
state.coordinate_scale_factor_xyz[2];
887 axes->SetRanges(unscaled_data_bounds);
888 axes->SetUseRanges(1);
889 axes->SetInputConnection(transgeometry->GetOutputPort());
890 axes->GetProperty()->SetColor(0, 0, 0);
891 axes->SetFontFactor(1.5);
892 axes->SetCornerOffset(0);
893 axes->SetNumberOfLabels(3);
894 axes->SetInertia(100);
895 axes->SetLabelFormat(
"%6.2g");
898 axes->SetCamera(renderer->GetActiveCamera());
900 if (
state.spacedim==2)
904 axes->ZAxisVisibilityOff();
908 axes->SetXLabel(
"x");
909 axes->SetYLabel(
"y");
910 axes->SetZLabel(
"z");
912 auto textprop=
axes->GetAxisLabelTextProperty();
913 textprop->ItalicOff();
915 textprop->SetFontFamilyToCourier();
916 textprop->SetColor(0,0,0);
918 textprop=
axes->GetAxisTitleTextProperty();
919 textprop->ItalicOff();
921 textprop->SetFontFamilyToCourier();
922 textprop->SetColor(0,0,0);
934 this->RTBuildDomainPipeline0<vtkUnstructuredGrid>(renderer);
936 this->RTBuildDomainPipeline0<vtkRectilinearGrid>(renderer);
vtkSmartPointer< vtkDataSet > GetVTKBoundaryDataSet()
Request boundary dataset.
Class to collect all data given on one grid.
vtkSmartPointer< vtkLookupTable > BuildLookupTable(RGBTable &xrgb, size_t size)
DataType GetDataType()
Request the data type of the dataset.
vtkSmartPointer< vtkIdList > GetCellList(std::string name)
Request celllist.
double coordinate_scale_factor_xyz[3]
int GetSpaceDimension()
Request the space dimension of the dataset.
std::vector< RGBPoint > RGBTable
vtkSmartPointer< vtkDataSet > GetVTKDataSet()
Request vtkDataset which contains all the data.
double coordinate_scale_factor
RGB point for color tables.