Sprout from IMPORT 2003-10-14 08:51:59 UTC nri <nri@opencascade.com> 'sources v1.2c'
Delete:
src/OBJECT/VISU_LookupTable.cxx
src/OBJECT/VISU_LookupTable.hxx
src/OBJECT/VISU_ScalarBarActor.cxx
src/OBJECT/VISU_ScalarBarActor.hxx
src/VISU_I/VISU_Convertor.cxx
src/VISU_I/VISU_Convertor.hxx
src/VISU_I/VISU_Convertor_impl.cxx
src/VISU_I/VISU_Convertor_impl.hxx
src/VISU_I/VISU_DatConvertor.cxx
src/VISU_I/VISU_DatConvertor.hxx
src/VISU_I/VISU_Extractor.cxx
src/VISU_I/VISU_Extractor.hxx
src/VISU_I/VISU_FieldTransform.cxx
src/VISU_I/VISU_FieldTransform.hxx
src/VISU_I/VISU_MedConvertor.cxx
src/VISU_I/VISU_MedConvertor.hxx
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_LookupTable.cxx
-// Author : Vitaliy Smetannikov
-// Module : VISU
-
-using namespace std;
-#include "VISU_LookupTable.hxx"
-
-VISU_LookupTable *VISU_LookupTable::New() {
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_LookupTable");
- if(ret)
- return (VISU_LookupTable*)ret;
- return new VISU_LookupTable;
-}
-
-VISU_LookupTable::VISU_LookupTable(int sze, int ext)
- : vtkLookupTable(sze, ext), myScale(1.0) {}
-
-int VISU_LookupTable::ComputeLogRange(float inRange[2], float outRange[2]){
- if(inRange[0] >= inRange[1])
- return -1;
- if(0.0 <= inRange[0] && 0.0 < inRange[1]){
- if(inRange[0] != 0.0)
- outRange[0] = log10((double)inRange[0]);
- else
- outRange[0] = log10((double)inRange[1]*1.0E-6);
- outRange[1] = log10((double)inRange[1]);
- return 0;
- }else if(inRange[0] < 0.0 && inRange[1] <= 0.0){
- outRange[0] = log10((double)-inRange[0]);
- outRange[1] = log10((double)-inRange[1]);
- return 1;
- }else
- return -1;
-}
-
-unsigned char* VISU_LookupTable::MapValue(float v) {
- if(GetScale() == VTK_SCALE_LOG10) {
- float aLowBound = log10(this->TableRange[0]);
- v = pow(10.0f,aLowBound + (v - aLowBound)*myScale);
- return vtkLookupTable::MapValue(v);
- }else{
- v = this->TableRange[0] + (v - this->TableRange[0])*myScale;
- return vtkLookupTable::MapValue(v);
- }
-}
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_LookupTable.h
-// Author : Vitaliy Smetannikov
-// Module : VISU
-
-#ifndef VISU_LookupTable_H
-#define VISU_LookupTable_H
-
-//#include <vtkLookupTable.h>
-#include "VTKViewer_Common.h"
-#include <vtkLogLookupTable.h>
-
-class VISU_LookupTable: public vtkLookupTable {
- public:
- vtkTypeMacro(VISU_LookupTable,vtkLogLookupTable);
- static VISU_LookupTable *New();
-
- float GetMapScale() { return myScale; }
- void SetMapScale(float theScale) { myScale = theScale; Modified(); }
-
- static int ComputeLogRange(float inRange[2], float outRange[2]);
- unsigned char *MapValue(float v);
-
- protected:
- VISU_LookupTable(int sze=256, int ext=256);
- ~VISU_LookupTable() {};
-
- float myScale;
-};
-#endif // VISU_LookupTable_H
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_ScalarBarActor.cxx
-// Author : Alexey PETROV
-// Module : VISU
-
-using namespace std;
-#include "VISU_ScalarBarActor.hxx"
-
-vtkCxxRevisionMacro(VISU_ScalarBarActor, "$Revision$");
-
-vtkCxxSetObjectMacro(VISU_ScalarBarActor,LookupTable,VISU_LookupTable);
-vtkCxxSetObjectMacro(VISU_ScalarBarActor,LabelTextProperty,vtkTextProperty);
-vtkCxxSetObjectMacro(VISU_ScalarBarActor,TitleTextProperty,vtkTextProperty);
-
-//------------------------------------------------------------------------------
-VISU_ScalarBarActor* VISU_ScalarBarActor::New(){
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_ScalarBarActor");
- if(ret)
- return (VISU_ScalarBarActor*)ret;
- return new VISU_ScalarBarActor;
-}
-
-VISU_ScalarBarActor::VISU_ScalarBarActor()
-{
- this->LookupTable = NULL;
- this->Position2Coordinate->SetValue(0.17, 0.8);
-
- this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
- this->PositionCoordinate->SetValue(0.82,0.1);
-
- this->MaximumNumberOfColors = 64;
- this->NumberOfLabels = 5;
- this->NumberOfLabelsBuilt = 0;
- this->Orientation = VTK_ORIENT_VERTICAL;
- this->Title = NULL;
-
- this->LabelTextProperty = vtkTextProperty::New();
- this->LabelTextProperty->SetFontSize(12);
- this->LabelTextProperty->SetBold(1);
- this->LabelTextProperty->SetItalic(1);
- this->LabelTextProperty->SetShadow(1);
- this->LabelTextProperty->SetFontFamilyToArial();
-
- this->TitleTextProperty = vtkTextProperty::New();
- this->TitleTextProperty->ShallowCopy(this->LabelTextProperty);
-
- this->LabelFormat = new char[8];
- sprintf(this->LabelFormat,"%s","%-#6.3g");
-
- this->TitleMapper = vtkTextMapper::New();
- this->TitleActor = vtkActor2D::New();
- this->TitleActor->SetMapper(this->TitleMapper);
- this->TitleActor->GetPositionCoordinate()->
- SetReferenceCoordinate(this->PositionCoordinate);
-
- this->TextMappers = NULL;
- this->TextActors = NULL;
-
- this->ScalarBar = vtkPolyData::New();
- this->ScalarBarMapper = vtkPolyDataMapper2D::New();
- this->ScalarBarMapper->SetInput(this->ScalarBar);
- this->ScalarBarActor = vtkActor2D::New();
- this->ScalarBarActor->SetMapper(this->ScalarBarMapper);
- this->ScalarBarActor->GetPositionCoordinate()->
- SetReferenceCoordinate(this->PositionCoordinate);
- this->LastOrigin[0] = 0;
- this->LastOrigin[1] = 0;
- this->LastSize[0] = 0;
- this->LastSize[1] = 0;
-}
-
-void VISU_ScalarBarActor::ReleaseGraphicsResources(vtkWindow *win)
-{
- this->TitleActor->ReleaseGraphicsResources(win);
- if (this->TextMappers != NULL )
- {
- for (int i=0; i < this->NumberOfLabelsBuilt; i++)
- {
- this->TextActors[i]->ReleaseGraphicsResources(win);
- }
- }
- this->ScalarBarActor->ReleaseGraphicsResources(win);
-}
-
-VISU_ScalarBarActor::~VISU_ScalarBarActor()
-{
- if (this->LabelFormat)
- {
- delete [] this->LabelFormat;
- this->LabelFormat = NULL;
- }
-
- this->TitleMapper->Delete();
- this->TitleActor->Delete();
-
- if (this->TextMappers != NULL )
- {
- for (int i=0; i < this->NumberOfLabelsBuilt; i++)
- {
- this->TextMappers[i]->Delete();
- this->TextActors[i]->Delete();
- }
- delete [] this->TextMappers;
- delete [] this->TextActors;
- }
-
- this->ScalarBar->Delete();
- this->ScalarBarMapper->Delete();
- this->ScalarBarActor->Delete();
-
- if (this->Title)
- {
- delete [] this->Title;
- this->Title = NULL;
- }
-
- this->SetLookupTable(NULL);
- this->SetLabelTextProperty(NULL);
- this->SetTitleTextProperty(NULL);
-}
-
-int VISU_ScalarBarActor::RenderOverlay(vtkViewport *viewport)
-{
- int renderedSomething = 0;
- int i;
-
- // Everything is built, just have to render
- if (this->Title != NULL)
- {
- renderedSomething += this->TitleActor->RenderOverlay(viewport);
- }
- this->ScalarBarActor->RenderOverlay(viewport);
- if( this->TextActors == NULL)
- {
- vtkWarningMacro(<<"Need a mapper to render a scalar bar");
- return renderedSomething;
- }
-
- for (i=0; i<this->NumberOfLabels; i++)
- {
- renderedSomething += this->TextActors[i]->RenderOverlay(viewport);
- }
-
- renderedSomething = (renderedSomething > 0)?(1):(0);
-
- return renderedSomething;
-}
-
-int VISU_ScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
-{
- int renderedSomething = 0;
- int i;
- int size[2];
-
- if (!this->LookupTable)
- {
- vtkWarningMacro(<<"Need a mapper to render a scalar bar");
- return 0;
- }
-
- if (!this->TitleTextProperty)
- {
- vtkErrorMacro(<<"Need title text property to render a scalar bar");
- return 0;
- }
-
- if (!this->LabelTextProperty)
- {
- vtkErrorMacro(<<"Need label text property to render a scalar bar");
- return 0;
- }
-
- // Check to see whether we have to rebuild everything
- int positionsHaveChanged = 0;
- if (viewport->GetMTime() > this->BuildTime ||
- (viewport->GetVTKWindow() &&
- viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
- {
- // if the viewport has changed we may - or may not need
- // to rebuild, it depends on if the projected coords chage
- int *barOrigin;
- barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
- size[0] =
- this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
- barOrigin[0];
- size[1] =
- this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
- barOrigin[1];
- if (this->LastSize[0] != size[0] ||
- this->LastSize[1] != size[1] ||
- this->LastOrigin[0] != barOrigin[0] ||
- this->LastOrigin[1] != barOrigin[1])
- {
- positionsHaveChanged = 1;
- }
- }
-
- // Check to see whether we have to rebuild everything
- if (positionsHaveChanged ||
- this->GetMTime() > this->BuildTime ||
- this->LookupTable->GetMTime() > this->BuildTime ||
- this->LabelTextProperty->GetMTime() > this->BuildTime ||
- this->TitleTextProperty->GetMTime() > this->BuildTime)
- {
-
- // Delete previously constructed objects
- //
- if (this->TextMappers != NULL )
- {
- for (i=0; i < this->NumberOfLabelsBuilt; i++)
- {
- this->TextMappers[i]->Delete();
- this->TextActors[i]->Delete();
- }
- delete [] this->TextMappers;
- delete [] this->TextActors;
- }
-
- // Build scalar bar object; determine its type
- //
- VISU_LookupTable *lut = this->LookupTable; //SALOME specific
- int isLogTable = lut->GetScale() == VTK_SCALE_LOG10;
-
- // we hard code how many steps to display
- int numColors = this->MaximumNumberOfColors;
- float *range = lut->GetRange();
-
- int numPts = 2*(numColors + 1);
- vtkPoints *pts = vtkPoints::New();
- pts->SetNumberOfPoints(numPts);
- vtkCellArray *polys = vtkCellArray::New();
- polys->Allocate(polys->EstimateSize(numColors,4));
- vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
- colors->SetNumberOfComponents(3);
- colors->SetNumberOfTuples(numColors);
-
- this->ScalarBarActor->SetProperty(this->GetProperty());
- this->ScalarBar->Initialize();
- this->ScalarBar->SetPoints(pts);
- this->ScalarBar->SetPolys(polys);
- this->ScalarBar->GetCellData()->SetScalars(colors);
- pts->Delete(); polys->Delete(); colors->Delete();
-
- // get the viewport size in display coordinates
- int *barOrigin, barWidth, barHeight;
- barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
- size[0] =
- this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
- barOrigin[0];
- size[1] =
- this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
- barOrigin[1];
- this->LastOrigin[0] = barOrigin[0];
- this->LastOrigin[1] = barOrigin[1];
- this->LastSize[0] = size[0];
- this->LastSize[1] = size[1];
-
- // Update all the composing objects
- this->TitleActor->SetProperty(this->GetProperty());
- this->TitleMapper->SetInput(this->Title);
- if (this->TitleTextProperty->GetMTime() > this->BuildTime)
- {
- // Shallow copy here so that the size of the title prop is not affected
- // by the automatic adjustment of its text mapper's size (i.e. its
- // mapper's text property is identical except for the font size
- // which will be modified later). This allows text actors to
- // share the same text property, and in that case specifically allows
- // the title and label text prop to be the same.
- this->TitleMapper->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
- this->TitleMapper->GetTextProperty()->SetJustificationToCentered();
- }
-
- // find the best size for the title font
- int titleSize[2];
- this->SizeTitle(titleSize, size, viewport);
-
- // find the best size for the ticks
- int labelSize[2];
- this->AllocateAndSizeLabels(labelSize, size, viewport,range);
- this->NumberOfLabelsBuilt = this->NumberOfLabels;
-
- // generate points
- float x[3]; x[2] = 0.0;
- float delta, val;
- if ( this->Orientation == VTK_ORIENT_VERTICAL )
- {
- barWidth = size[0] - 4 - labelSize[0];
- barHeight = (int)(0.86*size[1]);
- delta=(float)barHeight/numColors;
- for (i=0; i<numPts/2; i++)
- {
- x[0] = 0;
- x[1] = i*delta;
- pts->SetPoint(2*i,x);
- x[0] = barWidth;
- pts->SetPoint(2*i+1,x);
- }
- }
- else
- {
- barWidth = size[0];
- barHeight = (int)(0.4*size[1]);
- delta=(float)barWidth/numColors;
- for (i=0; i<numPts/2; i++)
- {
- x[0] = i*delta;
- x[1] = barHeight;
- pts->SetPoint(2*i,x);
- x[1] = 0;
- pts->SetPoint(2*i+1,x);
- }
- }
-
- //polygons & cell colors
- unsigned char *rgba, *rgb;
- vtkIdType ptIds[4];
- for (i=0; i<numColors; i++)
- {
- ptIds[0] = 2*i;
- ptIds[1] = ptIds[0] + 1;
- ptIds[2] = ptIds[1] + 2;
- ptIds[3] = ptIds[0] + 2;
- polys->InsertNextCell(4,ptIds);
-
- if ( isLogTable ){ //SALOME specific
- float rgbval = log10(range[0]) +
- i*(log10(range[1])-log10(range[0]))/(numColors -1);
- rgba = lut->MapValue(rgbval);
- }else{
- rgba = lut->MapValue(range[0] + (range[1] - range[0])*
- ((float)i /(numColors-1.0)));
- }
-
- rgb = colors->GetPointer(3*i); //write into array directly
- rgb[0] = rgba[0];
- rgb[1] = rgba[1];
- rgb[2] = rgba[2];
- }
-
- // Now position everything properly
- //
- if (this->Orientation == VTK_ORIENT_VERTICAL)
- {
- int sizeTextData[2];
-
- // center the title
- this->TitleActor->SetPosition(size[0]/2, 0.9*size[1]);
-
- for (i=0; i < this->NumberOfLabels; i++)
- {
- val = (float)i/(this->NumberOfLabels-1) *barHeight;
- this->TextMappers[i]->GetSize(viewport,sizeTextData);
- this->TextMappers[i]->GetTextProperty()->SetJustificationToLeft();
- this->TextActors[i]->SetPosition(barWidth+3,
- val - sizeTextData[1]/2);
- }
- }
- else
- {
- this->TitleActor->SetPosition(size[0]/2,
- barHeight + labelSize[1] + 0.1*size[1]);
- for (i=0; i < this->NumberOfLabels; i++)
- {
- this->TextMappers[i]->GetTextProperty()->SetJustificationToCentered();
- val = (float)i/(this->NumberOfLabels-1) * barWidth;
- this->TextActors[i]->SetPosition(val, barHeight + 0.05*size[1]);
- }
- }
-
- this->BuildTime.Modified();
- }
-
- // Everything is built, just have to render
- if (this->Title != NULL)
- {
- renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
- }
- this->ScalarBarActor->RenderOpaqueGeometry(viewport);
- for (i=0; i<this->NumberOfLabels; i++)
- {
- renderedSomething += this->TextActors[i]->RenderOpaqueGeometry(viewport);
- }
-
- renderedSomething = (renderedSomething > 0)?(1):(0);
-
- return renderedSomething;
-}
-
-void VISU_ScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
-{
- this->Superclass::PrintSelf(os,indent);
-
- if ( this->LookupTable )
- {
- os << indent << "Lookup Table:\n";
- this->LookupTable->PrintSelf(os,indent.GetNextIndent());
- }
- else
- {
- os << indent << "Lookup Table: (none)\n";
- }
-
- if (this->TitleTextProperty)
- {
- os << indent << "Title Text Property:\n";
- this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
- }
- else
- {
- os << indent << "Title Text Property: (none)\n";
- }
-
- if (this->LabelTextProperty)
- {
- os << indent << "Label Text Property:\n";
- this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
- }
- else
- {
- os << indent << "Label Text Property: (none)\n";
- }
-
- os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
- os << indent << "Maximum Number Of Colors: "
- << this->MaximumNumberOfColors << "\n";
- os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
- os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
-
- os << indent << "Orientation: ";
- if ( this->Orientation == VTK_ORIENT_HORIZONTAL )
- {
- os << "Horizontal\n";
- }
- else
- {
- os << "Vertical\n";
- }
-
- os << indent << "Label Format: " << this->LabelFormat << "\n";
-}
-
-void VISU_ScalarBarActor::ShallowCopy(vtkProp *prop)
-{
- VISU_ScalarBarActor *a = VISU_ScalarBarActor::SafeDownCast(prop);
- if ( a != NULL )
- {
- this->SetPosition2(a->GetPosition2());
- this->SetLookupTable(a->GetLookupTable());
- this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors());
- this->SetOrientation(a->GetOrientation());
- this->SetLabelTextProperty(a->GetLabelTextProperty());
- this->SetTitleTextProperty(a->GetTitleTextProperty());
- this->SetLabelFormat(a->GetLabelFormat());
- this->SetTitle(a->GetTitle());
- this->GetPositionCoordinate()->SetCoordinateSystem(
- a->GetPositionCoordinate()->GetCoordinateSystem());
- this->GetPositionCoordinate()->SetValue(
- a->GetPositionCoordinate()->GetValue());
- this->GetPosition2Coordinate()->SetCoordinateSystem(
- a->GetPosition2Coordinate()->GetCoordinateSystem());
- this->GetPosition2Coordinate()->SetValue(
- a->GetPosition2Coordinate()->GetValue());
- }
-
- // Now do superclass
- this->vtkActor2D::ShallowCopy(prop);
-}
-
-void VISU_ScalarBarActor::AllocateAndSizeLabels(int *labelSize, int *size,
- vtkViewport *viewport,
- float *range)
-{
- labelSize[0] = labelSize[1] = 0;
-
- this->TextMappers = new vtkTextMapper * [this->NumberOfLabels];
- this->TextActors = new vtkActor2D * [this->NumberOfLabels];
-
- char string[512];
-
- float val;
- int i;
-
- // TODO: this should be optimized, maybe by keeping a list of
- // allocated mappers, in order to avoid creation/destruction of
- // their underlying text properties (i.e. each time a mapper is
- // created, text properties are created and shallow-assigned a font size
- // which value might be "far" from the target font size).
-
- VISU_LookupTable *lut = this->LookupTable; //SALOME specific
- int isLogTable = lut->GetScale() == VTK_SCALE_LOG10;
-
- for (i=0; i < this->NumberOfLabels; i++)
- {
- this->TextMappers[i] = vtkTextMapper::New();
-
- if(isLogTable && 0 < i && i < this->NumberOfLabels - 1){ // SALOME specific
- float lval = log10(range[0]) + (float)i/(this->NumberOfLabels-1) *
- (log10(range[1])-log10(range[0]));
- val = pow(10,lval);
- }else{
- val = range[0] + (float)i/(this->NumberOfLabels-1) * (range[1]-range[0]);
- }
- sprintf(string, this->LabelFormat, val);
- this->TextMappers[i]->SetInput(string);
-
- // Shallow copy here so that the size of the label prop is not affected
- // by the automatic adjustment of its text mapper's size (i.e. its
- // mapper's text property is identical except for the font size
- // which will be modified later). This allows text actors to
- // share the same text property, and in that case specifically allows
- // the title and label text prop to be the same.
- this->TextMappers[i]->GetTextProperty()->ShallowCopy(
- this->LabelTextProperty);
-
- this->TextActors[i] = vtkActor2D::New();
- this->TextActors[i]->SetMapper(this->TextMappers[i]);
- this->TextActors[i]->SetProperty(this->GetProperty());
- this->TextActors[i]->GetPositionCoordinate()->
- SetReferenceCoordinate(this->PositionCoordinate);
- }
-
- if (this->NumberOfLabels)
- {
- int targetWidth, targetHeight;
-
- if ( this->Orientation == VTK_ORIENT_VERTICAL )
- {
- targetWidth = (int)(0.6*size[0]);
- targetHeight = (int)(0.86*size[1]/this->NumberOfLabels);
- }
- else
- {
- targetWidth = (int)(size[0]*0.8/this->NumberOfLabels);
- targetHeight = (int)(0.25*size[1]);
- }
-
- vtkTextMapper::SetMultipleConstrainedFontSize(viewport,
- targetWidth,
- targetHeight,
- this->TextMappers,
- this->NumberOfLabels,
- labelSize);
- }
-}
-
-void VISU_ScalarBarActor::SizeTitle(int *titleSize, int *size,
- vtkViewport *viewport)
-{
- titleSize[0] = titleSize[1] = 0;
-
- if (this->Title == NULL || !strlen(this->Title))
- {
- return;
- }
-
- int targetWidth, targetHeight;
-
- targetWidth = size[0];
- if ( this->Orientation == VTK_ORIENT_VERTICAL )
- {
- targetHeight = (int)(0.1*size[1]);
- }
- else
- {
- targetHeight = (int)(0.25*size[1]);
- }
-
- this->TitleMapper->SetConstrainedFontSize(
- viewport, targetWidth, targetHeight);
-
- this->TitleMapper->GetSize(viewport, titleSize);
-}
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_ScalarBarActor.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_ScalarBarActor_HeaderFile
-#define VISU_ScalarBarActor_HeaderFile
-
-#include "VTKViewer_Common.h"
-#include "VISU_LookupTable.hxx"
-#include <vtkPolyDataMapper2D.h>
-
-#define VTK_ORIENT_HORIZONTAL 0
-#define VTK_ORIENT_VERTICAL 1
-
-class VISU_ScalarBarActor : public vtkActor2D
-{
-public:
- vtkTypeRevisionMacro(VISU_ScalarBarActor,vtkActor2D);
- void PrintSelf(ostream& os, vtkIndent indent);
-
- // Description:
- // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
- // format, no title, and vertical orientation. The initial scalar bar
- // size is (0.05 x 0.8) of the viewport size.
- static VISU_ScalarBarActor *New();
-
- // Description:
- // Draw the scalar bar and annotation text to the screen.
- int RenderOpaqueGeometry(vtkViewport* viewport);
- int RenderTranslucentGeometry(vtkViewport*) { return 0; };
- int RenderOverlay(vtkViewport* viewport);
-
- // Description:
- // Release any graphics resources that are being consumed by this actor.
- // The parameter window could be used to determine which graphic
- // resources to release.
- virtual void ReleaseGraphicsResources(vtkWindow *);
-
- // Description:
- // Set/Get the vtkLookupTable to use. The lookup table specifies the number
- // of colors to use in the table (if not overridden), as well as the scalar
- // range.
- virtual void SetLookupTable(VISU_LookupTable*);
- vtkGetObjectMacro(LookupTable,VISU_LookupTable);
-
- // Description:
- // Set/Get the maximum number of scalar bar segments to show. This may
- // differ from the number of colors in the lookup table, in which case
- // the colors are samples from the lookup table.
- vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER);
- vtkGetMacro(MaximumNumberOfColors, int);
-
- // Description:
- // Set/Get the number of annotation labels to show.
- vtkSetClampMacro(NumberOfLabels, int, 0, 64);
- vtkGetMacro(NumberOfLabels, int);
-
- // Description:
- // Control the orientation of the scalar bar.
- vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
- vtkGetMacro(Orientation, int);
- void SetOrientationToHorizontal()
- {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
- void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
-
- // Description:
- // Set/Get the title text property.
- virtual void SetTitleTextProperty(vtkTextProperty *p);
- vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
-
- // Description:
- // Set/Get the labels text property.
- virtual void SetLabelTextProperty(vtkTextProperty *p);
- vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
-
- // Description:
- // Set/Get the format with which to print the labels on the scalar
- // bar.
- vtkSetStringMacro(LabelFormat);
- vtkGetStringMacro(LabelFormat);
-
- // Description:
- // Set/Get the title of the scalar bar actor,
- vtkSetStringMacro(Title);
- vtkGetStringMacro(Title);
-
- // Description:
- // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
- void ShallowCopy(vtkProp *prop);
-
-protected:
- VISU_ScalarBarActor();
- ~VISU_ScalarBarActor();
-
- VISU_LookupTable *LookupTable;
- vtkTextProperty *TitleTextProperty;
- vtkTextProperty *LabelTextProperty;
-
- int MaximumNumberOfColors;
- int NumberOfLabels;
- int NumberOfLabelsBuilt;
- int Orientation;
- char *Title;
- char *LabelFormat;
-
- vtkTextMapper **TextMappers;
- virtual void AllocateAndSizeLabels(int *labelSize, int *size,
- vtkViewport *viewport, float *range);
-
-private:
- vtkTextMapper *TitleMapper;
- vtkActor2D *TitleActor;
-
- vtkActor2D **TextActors;
-
- vtkPolyData *ScalarBar;
- vtkPolyDataMapper2D *ScalarBarMapper;
- vtkActor2D *ScalarBarActor;
-
- vtkTimeStamp BuildTime;
- int LastSize[2];
- int LastOrigin[2];
-
- void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
-
-private:
- VISU_ScalarBarActor(const VISU_ScalarBarActor&); // Not implemented.
- void operator=(const VISU_ScalarBarActor&); // Not implemented.
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Convertor.cxx
-// Author : Alexey PETROV
-// Module : VISU
-
-using namespace std;
-#include "VISU_Convertor.hxx"
-#include <fstream>
-#include <strstream>
-#include <vtkCellType.h>
-#include <qdir.h>
-#include <qfileinfo.h>
-#include <qstringlist.h>
-#include <memory>
-using namespace std;
-
-#ifdef DEBUG
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 1;
-#endif
-
-namespace VISU{
- TVtkCellInfoMap aVtkCellInfoMap;
- static int INIT = (
- aVtkCellInfoMap[VTK_VERTEX] = TVtkCellInfo("VTK_VERTEX",1),
- aVtkCellInfoMap[VTK_LINE] = TVtkCellInfo("VTK_LINE",2),
- aVtkCellInfoMap[VTK_TRIANGLE] = TVtkCellInfo("VTK_TRIANGLE",3),
- aVtkCellInfoMap[VTK_QUAD] = TVtkCellInfo("VTK_QUAD",4),
- aVtkCellInfoMap[VTK_TETRA] = TVtkCellInfo("VTK_TETRA",4),
- aVtkCellInfoMap[VTK_HEXAHEDRON] = TVtkCellInfo("VTK_HEXAHEDRON",8),
- aVtkCellInfoMap[VTK_WEDGE] = TVtkCellInfo("VTK_WEDGE",6),
- aVtkCellInfoMap[VTK_PYRAMID] = TVtkCellInfo("VTK_PYRAMID",5),
- 1);
-
- pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
- throw(std::runtime_error&)
- {
- bool isFamilyPresent = (theFamilyName != "");
- int aNbCells = 0, aCellsSize = 0;
- if(!isFamilyPresent){
- TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin();
- for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){
- const TConnForCellType& aConnForCellType = aCellsConnIter->second;
- if(!aConnForCellType.empty()){
- aNbCells += aConnForCellType.size();
- aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1);
- }
- }
- }else{
- TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
- if(aFamilyMapIter == myFamilyMap.end())
- throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
- const TFamily& aFamily = aFamilyMapIter->second;
- const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
- TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin();
- for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){
- const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
- if(!aSubMeshOnCellType.empty()){
- int tmp = aSubMeshOnCellType.size();
- aNbCells += tmp;
- int aVtkType = aSubMeshIter->first;
- int aVtkSize = aVtkCellInfoMap[aVtkType].mySize;
- aCellsSize += tmp*(aVtkSize+1);
- }
- }
- }
- return make_pair(aNbCells,aCellsSize);
- }
-
- void TMesh::CreateMeshOnNodes(){
- TMeshOnEntity& aMeshOnEntity = myMeshOnEntityMap[NODE_ENTITY];
- TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
- int jEnd = myPointsCoord.size()/myDim;
- aConnForCellType.resize(jEnd);
- for (int j = 0; j < jEnd; j++) aConnForCellType[j] = TMeshOnEntity::TConnect(1,j);
- }
-
- const TField* TMesh::GetField(const string& theFieldName) const {
- TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap;
- TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
- for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++)
- if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second);
- }
- return NULL;
- }
-
- const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
- throw(std::runtime_error&)
- {
- if(theFamilyName == "") return NULL;
- const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
- if(aFamilyMapIter == aFamilyMap.end())
- throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
- const VISU::TFamily& aFamily = aFamilyMapIter->second;
- return &aFamily;
- }
-
- TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
- throw(std::runtime_error&)
- {
- if(theFamilyName == "") return NULL;
- VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
- VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
- if(aFamilyMapIter == aFamilyMap.end())
- throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
- VISU::TFamily& aFamily = aFamilyMapIter->second;
- return &aFamily;
- }
-
- void TField::ShallowCopy(const TField& aField){
- myEntity = aField.myEntity;
- myMeshName = aField.myMeshName;
- myNbComp = aField.myNbComp;
- VISU::TField::TValField::const_iterator iter = aField.myValField.begin();
- for(; iter != aField.myValField.end(); iter++)
- myValField[iter->first];
- }
-}
-
-const VISU::TMeshMap& VISU_Convertor::GetMeshMap() throw(std::runtime_error&){
- if(!myIsDone) { myIsDone = true; Build();}
- return myMeshMap;
-}
-
-const VISU::TField& VISU_Convertor::GetField(const string& theMeshName,
- VISU::TEntity theEntity,
- const string& theFieldName)
- throw (std::runtime_error&)
-{
- if(!myIsDone) { myIsDone = true; Build();}
- VISU::TMeshMap::const_iterator aMeshMapIter = myMeshMap.find(theMeshName);
- if(aMeshMapIter == myMeshMap.end())
- throw std::runtime_error("GetField >> There is no mesh with the name !!!");
- const VISU::TMesh& aMesh = aMeshMapIter->second;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMesh.myMeshOnEntityMap.find(theEntity);
- if(aMeshOnEntityMapIter == aMesh.myMeshOnEntityMap.end())
- throw std::runtime_error("GetField >> There is no mesh with the entity !!!");
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
- VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.find(theFieldName);
- if(aFieldMapIter == aFieldMap.end())
- throw std::runtime_error("GetField >> There is no field with the name !!!");
- return aFieldMapIter->second;
-}
-
-string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){
- static QString aName;
- const string aUnits = aTime.second, tmp(aUnits.size(),' ');
- if(aUnits == "" || aUnits == tmp)
- aName.sprintf("%g, -",aTime.first);
- else
- aName.sprintf("%g, %s",aTime.first,aTime.second.c_str());
- aName = aName.simplifyWhiteSpace();
- return aName.latin1();
-}
-
-string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) {
- static QString aName;
- aName = QString(theName.c_str()).simplifyWhiteSpace();
- int iEnd = strlen(aName);
- static int VtkHighLevelLength = 12; //25
- if(iEnd > VtkHighLevelLength) iEnd = VtkHighLevelLength;
- char aNewName[iEnd+1];
- aNewName[iEnd] = '\0';
- strncpy(aNewName,aName,iEnd);
- replace(aNewName,aNewName+iEnd,' ','_');
- if(true || theTimeId == 0)
- aName = aNewName;
- else
- aName.sprintf("%s_%d",aNewName,theTimeId);
- return aName.latin1();
-}
-
-/*
-void parseFile(const char* theFileName) throw(std::runtime_error&){
- try{
- auto_ptr<VISU_Convertor> aCon(CreateConvertor(theFileName));
- const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap();
- VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
- for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
- const string& aMeshName = aMeshMapIter->first;
- const VISU::TMesh& aMesh = aMeshMapIter->second;
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
- //Import fields
- aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
- VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
- for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
- const string& aFieldName = aFieldMapIter->first;
- const VISU::TField& aField = aFieldMapIter->second;
- const VISU::TField::TValField& aValField = aField.myValField;
- VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
- for(; aValFieldIter != aValField.end(); aValFieldIter++){
- int aTimeStamp = aValFieldIter->first;
- aCon->GetFieldOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
- }
- }
- }
- //Importing groups
- const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
- VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
- for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
- const string& aGroupName = aGroupMapIter->first;
- aCon->GetMeshOnGroup(aMeshName,aGroupName);
- }
- //Import families
- aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- //aCon->GetMeshOnEntity(aMeshName,anEntity);
- const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
- for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
- const string& aFamilyName = aFamilyMapIter->first;
- aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
- }
- }
- //Import mesh on entity
- aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
- aCon->GetMeshOnEntity(aMeshName,anEntity);
- }
- }
- }catch(std::runtime_error& exc){
- MESSAGE("Follow exception was accured in file:"<<theFileName<<"\n"<<exc.what());
- }catch(...){
- MESSAGE("Unknown exception was accured in VISU_Convertor_impl in file:"<<theFileName);
- }
-}
-
-int main(int argc, char** argv){
- try{
- if(argc > 1){
- for(int i = 0; i < 1; i++){
- QFileInfo fi(argv[1]);
- if ( fi.exists() ) {
- if ( fi.isDir() ) {
- QDir aDir(fi.absFilePath());
- cout<<aDir.absPath()<<endl;
- QStringList aStringList = aDir.entryList("*.med",QDir::Files);
- int jEnd = aStringList.count();
- for(int j = 0; j < jEnd; j++)
- parseFile(aDir.filePath(aStringList[j]).latin1());
- }else
- parseFile(argv[1]);
- }
- }
- return 0;
- }
- }catch(std::runtime_error& exc){
- cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
- }catch(...){
- cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
- }
- return 1;
-}
-*/
-/*
-struct TRow{
- string myTitle;
- string myUnit;
- vector<float> myValues;
-};
-
-struct TTable2D{
- string myTitle;
- vector<string> myColumnUnits;
- vector<string> myColumnTitles;
- vector<TRow> myRows;
-};
-
-vector<TTable2D> aTables;
-
-int GetLine(ifstream& theStmIn, QString& theString){
- char tmp;
- ostrstream aStrOut;
- while(theStmIn.get(tmp)){
- aStrOut<<tmp;
- if(tmp == '\n') break;
- }
- aStrOut<<ends;
- auto_ptr<char> aRet(aStrOut.str());
- theString = aRet.get();
- return !theStmIn.eof();
-}
-
-int main(int argc, char** argv){
- try{
- if(argc > 1){
- ifstream aStmIn;
- aStmIn.open(argv[1]);
- QString aTmp;
- while(!aStmIn.eof()){
- //Find beginning of Table
- while(GetLine(aStmIn,aTmp) && aTmp.find("#TITLE:") != 0);
- if(aStmIn.eof()) return 0;
- cout<<"\n There is new Table2D with Title = ";
- TTable2D aTable2D;
- while(!aStmIn.eof() && aTmp != "\n"){
- if(aTmp.find("#TITLE:") == 0){
- int aLen = aTmp.find(":") + 1;
- aTmp.remove(0,aLen);
- QString aTitle = aTmp.stripWhiteSpace();
- aTable2D.myTitle = aTitle;
- cout<<aTitle<<endl;
- }else if(aTmp.find("#COLUMN_TITLES:") == 0){
- int aLen = aTmp.find(":") + 1;
- aTmp.remove(0,aLen);
- QStringList aStrList = QStringList::split("|",aTmp);
- cout<<"Its Column Titles : ";
- for(int i = 0; i < aStrList.count(); i++){
- aTmp = aStrList[i].stripWhiteSpace();
- aTable2D.myColumnTitles.push_back(aTmp.latin1());
- cout<<"\t"<<aTmp;
- }
- cout<<endl;
- }else if(aTmp.find("#COLUMN_UNITS:") == 0){
- int aLen = aTmp.find(":") + 1;
- aTmp.remove(0,aLen);
- QStringList aStrList = QStringList::split(" ",aTmp);
- cout<<"Its Column Units : ";
- for(int i = 0; i < aStrList.count(); i++){
- aTmp = aStrList[i].stripWhiteSpace();
- aTable2D.myColumnUnits.push_back(aTmp.latin1());
- cout<<"\t"<<aTmp;
- }
- cout<<endl;
- }else if(aTmp.find("#") == 0){
- //It is a comment
- }else if(aTmp.find("#TITLE:") > 0){
- QStringList aStrList = QStringList::split("#TITLE:",aTmp);
- QString aTitle = aStrList[1].stripWhiteSpace();
- TRow aRow;
- aRow.myTitle = aTitle;
- cout<<aTitle<<" : ";
- QStringList aValList = QStringList::split(" ",aStrList[0]);
- for(int i = 0; i < aValList.count(); i++){
- float aVal = aValList[i].toFloat();
- aRow.myValues.push_back(aVal);
- cout<<"\t"<<aVal;
- }
- aTable2D.myRows.push_back(aRow);
- cout<<endl;
- }else{
- QStringList aValList = QStringList::split(" ",aTmp);
- TRow aRow;
- for(int i = 0; i < aValList.count(); i++){
- float aVal = aValList[i].toFloat();
- aRow.myValues.push_back(aVal);
- cout<<"\t"<<aVal;
- }
- aTable2D.myRows.push_back(aRow);
- cout<<endl;
- }
- GetLine(aStmIn,aTmp);
- }
- }
- aStmIn.close();
- return 0;
- }
- }catch(std::runtime_error& exc){
- cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
- }catch(...){
- cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
- }
- return 1;
-}
-*/
-/*
-#include "VISU_Extractor.hxx"
-#include "VISU_FieldTransform.hxx"
-#include "VISU_LookupTable.hxx"
-#include "VISU_ScalarBarActor.hxx"
-
-#include <vtkRenderWindow.h>
-#include <vtkRenderer.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkActor.h>
-
-#include <vtkUnstructuredGridReader.h>
-#include <vtkDataSetMapper.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkDataSet.h>
-#include <vtkUnstructuredGridWriter.h>
-
-#include <vtkAppendPolyData.h>
-#include <vtkCutter.h>
-#include <vtkPlane.h>
-#include <vtkCellDataToPointData.h>
-#include <vtkPolyDataWriter.h>
-
-static float EPS = 1.0E-3;
-const float PI = 3.1415;
-extern float* GetIdent(float theR[3][3]);
-extern float* GetRx(float theRx[3][3], float thaAng);
-extern float* GetRy(float theRy[3][3], float thaAng);
-extern float* GetRz(float theRz[3][3], float thaAng);
-extern void MulMatrix(float C[3][3], const float A[3][3], const float B[3][3]); // C = A*B;
-extern void Sub(float C[3], const float A[3], float B[3]); // AxB
-extern float DotMul(const float A[3], const float B[3]); // A*B;
-extern void Mul(float C[3], const float A[3], float B[3]); // AxB
-extern void Mul(float C[3], const float A[3], float B); // A*B;
-extern void CorrectPnt(float thePnt[3], const float BoundPrj[3]);
-extern void GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]);
-
-typedef map<float,float> TXYMap;
-typedef vector<TXYMap> TCurveVect;
-
-void FillCurveXYMap(float theBasePnt[3], float theDir[3], float theBndDist,
- vtkPolyData* thePolyData, TXYMap& theXYMap)
-{
- int aNbPoints = thePolyData->GetNumberOfPoints();
- //cout<<"aNbPoints = "<<aNbPoints<<"\n";
- vtkPointData *aPointData = thePolyData->GetPointData();
- vtkScalars *aScalars = aPointData->GetScalars();
- float aPnt[3], aVect[3], aDist;
- for(int i = 0; i < aNbPoints; i++){
- thePolyData->GetPoint(i,aPnt);
- Sub(aVect,theBasePnt,aPnt);
- aDist = DotMul(aVect,theDir) / theBndDist;
- // the workaround
- if(aDist < 0.0) aDist = 0.0;
- if(aDist > 1.0) aDist = 1.0;
- theXYMap[aDist] = aScalars->GetScalar(i);
- //cout<<aDist<<"\t"<<theXYMap[aDist]<<endl;
- }
-}
-
-void PrintTable(const TCurveVect& theCurveVect){
- ofstream aStm;
- QString aFileName;
- for(int i = 0, iEnd = theCurveVect.size(); i < iEnd; i++){
- aFileName.sprintf("/users/%s/aCurve_%d.xls",getenv("USER"),i);
- aStm.open(aFileName.latin1());
- const TXYMap& aXYMap = theCurveVect[i];
- TXYMap::const_iterator aXYMapIter = aXYMap.begin();
- for(; aXYMapIter != aXYMap.end(); aXYMapIter++){
- float aX = aXYMapIter->first, aY = aXYMapIter->second;
- aStm<<aX<<"\t"<<aY<<endl;
- }
- aStm.close();
- }
-}
-
-int main(int argc, char** argv){
- try{
- if(argc > 1){
- vtkRenderWindow *renWin = vtkRenderWindow::New();
- vtkRenderer *ren = vtkRenderer::New();
- renWin->AddRenderer(ren);
- ren->GetActiveCamera()->ParallelProjectionOn();
- vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
- iren->SetRenderWindow(renWin);
- VISU_Convertor* aConvertor = CreateConvertor(argv[1]);
- const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap();
- VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
- if(aMeshMapIter == aMeshMap.end()) return 0;
- const string& aMeshName = aMeshMapIter->first;
- const VISU::TMesh& aMesh = aMeshMapIter->second;
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
- //Import fields
- aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
- VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
- if(aFieldMapIter == aFieldMap.end()) return 0;
- const string& aFieldName = aFieldMapIter->first;
- const VISU::TField& aField = aFieldMapIter->second;
- const VISU::TField::TValField& aValField = aField.myValField;
- VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
- if(aValFieldIter == aValField.end()) return 0;
- int aTimeStamp = aValFieldIter->first;
- vtkUnstructuredGridReader* aReader =
- aConvertor->GetFieldOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
- VISU_Extractor *anExtractor = VISU_Extractor::New();
- anExtractor->Extract(aReader,aFieldName,0,aField.myNbComp,anEntity);
- vtkUnstructuredGrid *aDataSet = anExtractor->GetUnstructuredGridOutput();
- VISU_FieldTransform* aFieldTransform = VISU_FieldTransform::New();
- aFieldTransform->SetInput(aDataSet);
- //if(argc > 2) aFieldTransform->SetTransformFunction(&log10);
- vtkDataSetMapper *aMapper = vtkDataSetMapper::New();
- float aScalarRange[2], myBounds[6];
- anExtractor->GetUnstructuredGridOutput()->GetScalarRange(aScalarRange);
- int aNumberOfColors = 64, aNumberOfLabels = 5;
- aDataSet->GetBounds(myBounds);
- cout<<"myBounds : \n";
- cout<<myBounds[0]<<"\t"<<myBounds[2]<<"\t"<<myBounds[4]<<endl;
- cout<<myBounds[1]<<"\t"<<myBounds[3]<<"\t"<<myBounds[5]<<endl;
- //Reused from CutPlanes
- //---------------------------------------------------------------------
- float myRotation[3][3];
- float myAng[3] = {0.0, 0.0, 0.0}, myDir[3], myInvDir[3], myBoundPrj[3], myDBPrj;
- int myNbPlanes = 1, myBasePlane = 0; //XY;
- if(argc > 2) myBasePlane = atoi(argv[2]);
- vtkAppendPolyData *myAppendPolyData = vtkAppendPolyData::New();
-
- float aRx[3][3], aRy[3][3], aRz[3][3];
- int iPlane = 0;
- if(myBasePlane == 0){ // X-Y
- if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
- if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
- ::MulMatrix(myRotation,aRx,aRy);
- iPlane = 2;
- }else if(myBasePlane == 1){ // Y-Z
- if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
- if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
- ::MulMatrix(myRotation,aRy,aRz);
- iPlane = 0;
- }else if(myBasePlane == 2){ // Z-X
- if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
- if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
- ::MulMatrix(myRotation,aRz,aRx);
- iPlane = 1;
- }
- for(int i = 0; i < 3; i++) myDir[i] = myRotation[i][iPlane];
- ::Mul(myInvDir,myDir,-1.0);
- ::GetBoundProject(myBoundPrj, myBounds, myDir);
- if(MYDEBUG) MESSAGE("myDir "<<myDir[0]<<"; "<<myDir[1]<<"; "<<myDir[2]);
-
- myDBPrj = 0.5*myBoundPrj[2];
- vtkCutter *aCutPlane = vtkCutter::New();
- aCutPlane->SetInput(aFieldTransform->GetUnstructuredGridOutput());
- vtkPlane *aPlane = vtkPlane::New();
- int i = 1;
- float aOrig[3];
- Mul(aOrig,myDir,myBoundPrj[0] + i*myDBPrj);
- if(0 && MYDEBUG) MESSAGE("aOrig["<<i<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
- aPlane->SetOrigin(aOrig);
- if(i == 0) aPlane->SetNormal(myInvDir);
- else aPlane->SetNormal(myDir);
- aCutPlane->SetCutFunction(aPlane);
- aPlane->Delete();
- myAppendPolyData->AddInput(aCutPlane->GetOutput());
- aCutPlane->Delete();
-
- //CutLines specific
- //---------------------------------------------------------------------
- float myDirPln[3], myDirLn[3], myBoundPrjLn[3], myBasePnt[3];
- if(argc > 3) myBasePlane = atoi(argv[3]);
- else myBasePlane = myBasePlane + 1;
- if(argc > 4) myNbPlanes = atoi(argv[4]);
- TCurveVect aCurveVect(myNbPlanes); //Declaration of Curve container
- vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
- if(myBasePlane == 0){ // X-Y
- if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
- if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
- ::MulMatrix(myRotation,aRx,aRy);
- iPlane = 2;
- }else if(myBasePlane == 1){ // Y-Z
- if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
- if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
- ::MulMatrix(myRotation,aRy,aRz);
- iPlane = 0;
- }else if(myBasePlane == 2){ // Z-X
- if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
- if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
- ::MulMatrix(myRotation,aRz,aRx);
- iPlane = 1;
- }
- for(int i = 0; i < 3; i++) myDirPln[i] = myRotation[i][iPlane];
- // Get Direction of CutLines and its Bounds
- ::Mul(myDirLn,myDirPln,myDir);
- ::GetBoundProject(myBoundPrjLn, myBounds, myDirLn);
- Mul(myBasePnt,myDirLn,myBoundPrjLn[0]);
- CorrectPnt(myBasePnt,myBounds);
- cout<<"myBasePnt : "<<myBasePnt[0]<<"\t"<<myBasePnt[1]<<"\t"<<myBasePnt[2]<<endl;
- cout<<"myDirLn : "<<myDirLn[0]<<"\t"<<myDirLn[1]<<"\t"<<myDirLn[2]<<endl;
- //-----------------------------------------
- ::Mul(myInvDir,myDirPln,-1.0);
- ::GetBoundProject(myBoundPrj, myBounds, myDirPln);
- int aNbPlanes = myNbPlanes;
- if (aNbPlanes > 1 ) {
- myDBPrj = myBoundPrj[2]/(aNbPlanes - 1);
- for (int i = 0; i < aNbPlanes; i++){
- vtkCutter *aCutPlane = vtkCutter::New();
- aCutPlane->SetInput(myAppendPolyData->GetOutput());
- vtkPlane *aPlane = vtkPlane::New();
- float aOrig[3];
- Mul(aOrig,myDirPln,myBoundPrj[0] + i*myDBPrj);
- if(0 && MYDEBUG) MESSAGE("aOrig["<<i<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
- aPlane->SetOrigin(aOrig);
- if(i == 0) aPlane->SetNormal(myInvDir);
- else aPlane->SetNormal(myDirPln);
- aCutPlane->SetCutFunction(aPlane);
- aPlane->Delete();
- vtkPolyData *aPolyData = aCutPlane->GetOutput();
- aPolyData->Update();
- anAppendPolyData->AddInput(aPolyData);
- FillCurveXYMap(myBasePnt,myDirLn,myBoundPrjLn[2],aPolyData,aCurveVect[i]);
- aCutPlane->Delete();
- string aFileName("/users/");
- aFileName = aFileName + getenv("USER") + "/" + "CutLine" + dtos("-%d.vtk",i);
- vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
- aWriter->SetFileName(aFileName.c_str());
- aWriter->SetInput(anAppendPolyData->GetInput(i));
- //aWriter->SetInput(aCutPlane->GetOutput());
- aWriter->Write();
- aWriter->Delete();
- }
- }else{
- myDBPrj = myBoundPrj[2]/2.0;
- int i = 1;
- vtkCutter *aCutPlane = vtkCutter::New();
- aCutPlane->SetInput(myAppendPolyData->GetOutput());
- vtkPlane *aPlane = vtkPlane::New();
- float aOrig[3];
- Mul(aOrig,myDirPln,myBoundPrj[0] + i*myDBPrj);
- if(0 && MYDEBUG) MESSAGE("aOrig["<<i<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
- aPlane->SetOrigin(aOrig);
- if(i == 0) aPlane->SetNormal(myInvDir);
- else aPlane->SetNormal(myDirPln);
- aCutPlane->SetCutFunction(aPlane);
- aPlane->Delete();
- vtkPolyData *aPolyData = aCutPlane->GetOutput();
- aPolyData->Update();
- anAppendPolyData->AddInput(aPolyData);
- FillCurveXYMap(myBasePnt,myDirLn,myBoundPrjLn[2],aPolyData,aCurveVect[i]);
- aCutPlane->Delete();
- }
-
- PrintTable(aCurveVect);
- aMapper->SetInput(anAppendPolyData->GetOutput());
-
- vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
- string aFileName("/users/");
- aFileName = aFileName + getenv("USER") + "/" + "CutLines.vtk";
- aWriter->SetFileName(aFileName.c_str());
- aWriter->SetInput(anAppendPolyData->GetOutput());
- aWriter->Write();
- aWriter->Delete();
-
- //aMapper->SetInput(myAppendPolyData->GetOutput());
-
- //aMapper->SetInput(aFieldTransform->GetUnstructuredGridOutput());
- aMapper->ScalarVisibilityOn();
- VISU_LookupTable* aActorLookupTbl = VISU_LookupTable::New();
- //if(argc > 2) aActorLookupTbl->SetLog(true);
- aActorLookupTbl->SetHueRange(0.667,0.0);
- aActorLookupTbl->SetNumberOfColors(aNumberOfColors);
- aActorLookupTbl->SetTableRange(aScalarRange[0],aScalarRange[1]); //
- aActorLookupTbl->SetMapScale(1.);
- aActorLookupTbl->Build();
- aMapper->SetLookupTable(aActorLookupTbl);
- aMapper->SetScalarRange(aScalarRange);
- aActorLookupTbl->Delete();
-
- vtkActor* aActor = vtkActor::New();
- aActor->SetMapper(aMapper);
-
- VISU_ScalarBarActor* aBar = VISU_ScalarBarActor::New();
- VISU_LookupTable* aBarLookupTbl = VISU_LookupTable::New();
- //if(argc > 2) aBarLookupTbl->SetLog(true);
- aBarLookupTbl->SetHueRange(0.667,0.0);
- aBarLookupTbl->SetNumberOfColors(aNumberOfColors);
- aBarLookupTbl->SetTableRange(aScalarRange[0],aScalarRange[1]); //
- aBarLookupTbl->Build();
- aBar->SetLookupTable(aBarLookupTbl);
- aBarLookupTbl->Delete();
-
- aBar->SetTitle(aFieldName.c_str());
- aBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
- aBar->SetNumberOfLabels(aNumberOfLabels);
-
- vtkProperty* aProperty = aActor->GetProperty();
- aProperty->SetSpecularColor( 1, 1, 1);
- aProperty->SetSpecular( 0.3 );
- aProperty->SetSpecularPower( 20 );
- aProperty->SetAmbient( 0.2);
- aProperty->SetDiffuse( 0.8 );
- aProperty->EdgeVisibilityOn();
-
- ren->AddActor(aActor);
- ren->AddActor2D(aBar);
-
- renWin->Render();
- iren->Start();
- return 1;
- }
- }
- }catch(std::runtime_error& exc){
- cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
- }catch(...){
- cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
- }
- return 1;
-}
-*/
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Convertor.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_Convertor_HeaderFile
-#define VISU_Convertor_HeaderFile
-
-#include <stdio.h>
-
-#include <algorithm>
-#include <iterator>
-#include <list>
-#include <map>
-#include <memory>
-#include <numeric>
-#include <set>
-#include <utility>
-#include <vector>
-#include <string>
-#include <stdexcept>
-
-#include <qstring.h>
-
-#include "utilities.h"
-#ifndef MESSAGE
-#define MESSAGE(msg) cout<<msg<<endl
-#endif
-
-
-//class vtkUnstructuredGridReader;
-#include "vtkUnstructuredGridReader.h"
-
-namespace VISU{
- class TVtkCellInfo{
- public:
- TVtkCellInfo() {}
- TVtkCellInfo(const char* theName, int theSize) :
- myName(theName), mySize(theSize) {}
- const char* myName;
- int mySize;
- };
- typedef std::map<int,TVtkCellInfo> TVtkCellInfoMap;
- extern TVtkCellInfoMap aVtkCellInfoMap;
-
- enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
- //enum TEntity {CELL_ENTITY, FACE_ENTITY, EDGE_ENTITY, NODE_ENTITY};
- template <class _Tp> class vtk_ptr {
- private:
- _Tp* _M_ptr;
- public:
- typedef _Tp element_type;
- explicit vtk_ptr(_Tp* __p = 0) : _M_ptr(__p) {}
- vtk_ptr(const vtk_ptr& __a) : _M_ptr(0) {}
- vtk_ptr(vtk_ptr& __a) : _M_ptr(__a.release()) {}
- vtk_ptr& operator=(const vtk_ptr& __a) { return *this;}
- vtk_ptr& operator=(vtk_ptr& __a) {
- if (&__a != this) {
- if(_M_ptr) _M_ptr->Delete();
- _M_ptr = __a.release();
- }
- return *this;
- }
- ~vtk_ptr() {
- if(_M_ptr) _M_ptr->Delete();
- _M_ptr = 0;
- }
- _Tp& operator*() const { return *_M_ptr;}
- _Tp* operator->() const { return _M_ptr;}
- _Tp* get() const { return _M_ptr;}
- _Tp* release() {
- _Tp* __tmp = _M_ptr;
- _M_ptr = 0;
- return __tmp;
- }
- void reset(_Tp* __p = 0) {
- if(_M_ptr) _M_ptr->Delete();
- _M_ptr = __p;
- }
- };
- typedef vtk_ptr<vtkUnstructuredGridReader> TVTKReader;
-
- typedef std::set<std::string> TBindGroups;
-
- struct TFamily{
- TVTKReader myStorage;
- int myId;
- string myName;
- TEntity myEntity;
- TBindGroups myGroups;
- typedef std::set<int> TSubMeshOnCellType;
- typedef std::map<int,TSubMeshOnCellType> TSubMesh;
- TSubMesh mySubMesh;
- };
- typedef std::map<std::string,TFamily> TFamilyMap;
-
- struct TField{
- int myId;
- string myName;
- TEntity myEntity;
- string myMeshName;
- int myNbComp;
- typedef std::vector<float> TValForCellsWithType;
- typedef std::map<int,TValForCellsWithType> TValForCells;
- typedef std::pair<double,std::string> TTime;
- typedef std::vector<string> TCompNames;
- typedef std::vector<string> TUnitNames;
- struct TValForTime{
- TVTKReader myStorage;
- int myId;
- TTime myTime;
- TValForCells myValForCells;
- };
- typedef std::map<int,TValForTime> TValField;
- TValField myValField;
- TCompNames myCompNames;
- TUnitNames myUnitNames;
- void ShallowCopy(const TField& aField);
- };
- typedef map<string,TField> TFieldMap;
-
- struct TMeshOnEntity{
- TVTKReader myStorage;
- string myMeshName;
- TEntity myEntity;
- typedef vector<int> TConnect;
- typedef vector<TConnect> TConnForCellType;
- typedef map<int,TConnForCellType> TCellsConn;
- TCellsConn myCellsConn;
- TFamilyMap myFamilyMap;
- TFieldMap myFieldMap;
- pair<int,int> GetCellsDims(const string& theFamilyName = "") const
- throw(std::runtime_error&);
- };
- typedef std::map<TEntity,TMeshOnEntity> TMeshOnEntityMap;
- const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName)
- throw(std::runtime_error&);
- TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName)
- throw(std::runtime_error&);
-
- typedef std::pair<std::string,TEntity> TFamilyAndEntity;
- typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
- struct TGroup{
- TVTKReader myStorage;
- string myName;
- string myMeshName;
- TFamilyAndEntitySet myFamilyAndEntitySet;
- };
- typedef std::map<std::string,TGroup> TGroupMap;
-
- struct TMesh{
- int myDim;
- string myName;
- typedef vector<float> TPointsCoord;
- TPointsCoord myPointsCoord;
- TMeshOnEntityMap myMeshOnEntityMap;
- TGroupMap myGroupMap;
- void CreateMeshOnNodes();
- const TField* GetField(const string& theFieldName) const;
- };
- typedef std::map<std::string,TMesh> TMeshMap;
-};
-
-class VISU_Convertor{
-protected:
- std::string myName;
- VISU::TMeshMap myMeshMap;
- int myIsDone;
-public:
- virtual ~VISU_Convertor(){};
- virtual const string& GetName() { return myName;}
- virtual int IsDone() const { return myIsDone;}
- typedef vtkUnstructuredGridReader OutputType;
- virtual VISU_Convertor* Build() throw (std::runtime_error&) = 0;
- virtual OutputType* GetMeshOnEntity(const string& theMeshName,
- const VISU::TEntity& theEntity,
- const string& theFamilyName = "")
- throw(std::runtime_error&) = 0;
- virtual OutputType* GetMeshOnGroup(const string& theMeshName,
- const string& theGroupName)
- throw(std::runtime_error&) = 0;
- virtual OutputType* GetFieldOnMesh(const string& theMeshName,
- const VISU::TEntity& theEntity,
- const string& theFieldName,
- int theStampsNum)
- throw(std::runtime_error&) = 0;
- virtual const VISU::TMeshMap& GetMeshMap() throw(std::runtime_error&);
- virtual const VISU::TField& GetField(const string& theMeshName, VISU::TEntity theEntity,
- const string& theFieldName)
- throw(std::runtime_error&);
- static string GenerateName(const VISU::TField::TTime& aTime);
- static string GenerateName(const string& theName, unsigned int theTimeId);
-};
-
-template<class T> std::string dtos(const string& fmt, T val){
- static QString aString;
- aString.sprintf(fmt.c_str(),val);
- return aString.latin1();
-}
-extern "C"{
- VISU_Convertor* CreateMedConvertor(const std::string& theFileName) throw(std::runtime_error&);
- VISU_Convertor* CreateDatConvertor(const std::string& theFileName) throw(std::runtime_error&);
- VISU_Convertor* CreateConvertor(const std::string& theFileName) throw(std::runtime_error&);
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Convertor_impl.cxx
-// Author : Alexey PETROV
-// Module : VISU
-
-using namespace std;
-#include "VISU_Convertor_impl.hxx"
-
-#include <vtkUnstructuredGridReader.h>
-#include <qstring.h>
-#include <qfileinfo.h>
-#include <vtkCellType.h>
-#include <valarray>
-#include <memory>
-using namespace std;
-
-#ifdef DEBUG
-static int MYDEBUG = 0;
-static int MYDEBUGWITHFILES = 0;
-#else
-static int MYDEBUG = 0;
-static int MYDEBUGWITHFILES = 0;
-#endif
-static int PRECISION = 7;
-
-#define MED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \
- {MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES}
-Med2vtk med2vtk[MED_NBR_GEOMETRIE_MAILLE] = {
- MED2VTK(MED_POINT1,VTK_VERTEX,1),
- MED2VTK(MED_SEG2,VTK_LINE,2),
- MED2VTK(MED_SEG3,VTK_LINE,2),
- MED2VTK(MED_TRIA3,VTK_TRIANGLE,3),
- MED2VTK(MED_TRIA6,VTK_TRIANGLE,3),
- MED2VTK(MED_QUAD4,VTK_QUAD,4),
- MED2VTK(MED_QUAD8,VTK_QUAD,4),
- MED2VTK(MED_TETRA4,VTK_TETRA,4),
- MED2VTK(MED_TETRA10,VTK_TETRA,4),
- MED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8),
- MED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8),
- MED2VTK(MED_PENTA6,VTK_WEDGE,6),
- MED2VTK(MED_PENTA15,VTK_WEDGE,6),
- MED2VTK(MED_PYRA5,VTK_PYRAMID,5),
- MED2VTK(MED_PYRA13,VTK_PYRAMID,5)
-};
-#undef MED2VTK
-
-extern "C" {
- VISU_Convertor* CreateConvertor(const string& theFileName) throw(std::runtime_error&){
- if(QFileInfo(theFileName.c_str()).extension(false) == "med")
- return CreateMedConvertor(theFileName);
- else
- return CreateDatConvertor(theFileName);
- }
-
- int getNbMedConnect(int theMedType, int theMedEntity, int theMeshDim){
- int anElemDim = theMedType / 100, nsup = 0;
- if(theMedEntity == VISU::CELL_ENTITY && anElemDim < theMeshDim) nsup = 1;
- return nsup + theMedType % 100;
- }
-
- int getNbMedNodes(int geom){
- return geom % 100;
- }
-
- int getIdMedType(int medType){
- for(int i = 0; i < MED_NBR_GEOMETRIE_MAILLE; i++)
- if(med2vtk[i].medType == medType) return i;
- return -1;
- }
-}
-
-VISU_Convertor_impl::VISU_Convertor_impl() {
- myIsDone = false;
-}
-
-VISU_Convertor_impl::~VISU_Convertor_impl() {}
-
-VISU_Convertor::OutputType* VISU_Convertor_impl::GetMeshOnEntity(const string& theMeshName,
- const VISU::TEntity& theEntity,
- const string& theFamilyName)
- throw (std::runtime_error&)
-{
- if(!myIsDone) { myIsDone = true; Build();}
- if(MYDEBUG)
- MESSAGE("GetMeshOnEntity - theMeshName = '"<<theMeshName<<
- "'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
- //Cheching possibility do the query
- if(myMeshMap.find(theMeshName) == myMeshMap.end())
- throw std::runtime_error("MeshOnEntityToString >> There is no mesh with the name!!!");
- VISU::TMesh& aMesh = myMeshMap[theMeshName];
- VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- if(aMeshOnEntityMap.find(theEntity) == aMeshOnEntityMap.end())
- throw std::runtime_error("MeshOnEntityToString >> There is no mesh on the entity!!!");
- VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMap[theEntity];
- VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName);
- VISU::TVTKReader* pReader;
- if(pFamily != NULL)
- pReader = &(pFamily->myStorage);
- else
- pReader = &(aMeshOnEntity.myStorage);
- VISU::TVTKReader& aReader = *pReader;
- //Main part of code
- if(aReader.get() == NULL){
- LoadMeshOnEntity(aMeshOnEntity,theFamilyName);
- ostrstream strOut;
- strOut<<GetHead(theMeshName + dtos("-%d-",theEntity) + theFamilyName);
- strOut<<GetPoints(aMesh);
- pair<int,int> aCellsDim = aMeshOnEntity.GetCellsDims(theFamilyName);
- int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second;
- ostrstream strCellsOut, strTypesOut;
- GetCells(strCellsOut,strTypesOut,aMeshOnEntity,theFamilyName);
- strCellsOut<<ends;
- strTypesOut<<ends;
- strOut<<"CELLS "<<aNbCells<<"\t"<<aCellsSize<<endl;
- auto_ptr<char> aRet(strCellsOut.str());
- strOut<<aRet.get()<<endl;
- strOut<<"CELL_TYPES "<<aNbCells<<endl;
- aRet.reset(strTypesOut.str());
- strOut<<aRet.get()<<endl;
- strOut<<ends;
- aReader.reset(OutputType::New());
- //aReader = OutputType::New();
- //aReader->DebugOn();
- aReader->ReadFromInputStringOn();
- aRet.reset(strOut.str());
- aReader->SetInputString(aRet.get());
- //aReader->Update();
- //aReader->Print(cout);
- if(MYDEBUGWITHFILES){
- string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
- string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1();
- string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-";
- aFileName += aMeshName + dtos("-%d-",theEntity) + aFamilyName + "-Conv.vtk";
- ofstream stmOut(aFileName.c_str(),ios::out);
- stmOut<<aRet.get();
- }
- }
- return aReader.get();
- //return aReader;
-}
-
-VISU_Convertor::OutputType* VISU_Convertor_impl::GetMeshOnGroup(const string& theMeshName,
- const string& theGroupName)
- throw(std::runtime_error&)
-{
- if(!myIsDone) { myIsDone = true; Build();}
- if(MYDEBUG) MESSAGE("GetMeshOnGroup - theMeshName = '"<<theMeshName<<
- "'; theGroupName = '"<<theGroupName<<"'");
- //Cheching possibility do the query
- if(myMeshMap.find(theMeshName) == myMeshMap.end())
- throw std::runtime_error("GetMeshOnGroup >> There is no mesh with the name!!!");
- VISU::TMesh& aMesh = myMeshMap[theMeshName];
- VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
- VISU::TGroupMap::iterator aGroupMapIter = aGroupMap.find(theGroupName);
- if(aGroupMapIter == aGroupMap.end())
- throw std::runtime_error("GetMeshOnGroup >> There is no the group in the mesh!!!");
- VISU::TGroup& aGroup = aGroupMapIter->second;
- const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup.myFamilyAndEntitySet;
- VISU::TVTKReader& aReader = aGroup.myStorage;
- if(aReader.get() == NULL){
- LoadMeshOnGroup(aMesh,aFamilyAndEntitySet);
- ostrstream strOut;
- strOut<<GetHead(theMeshName + "-" + theGroupName);
- strOut<<GetPoints(aMesh);
- VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
- int aNbCells = 0, aCellsSize = 0;
- ostrstream strCellsOut, strTypesOut;
- for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
- const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
- const string& aFamilyName = aFamilyAndEntity.first;
- const VISU::TEntity& anEntity = aFamilyAndEntity.second;
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- pair<int,int> aCellsDim = aMeshOnEntity.GetCellsDims(aFamilyName);
- aNbCells += aCellsDim.first;
- aCellsSize += aCellsDim.second;
- GetCells(strCellsOut,strTypesOut,aMeshOnEntity,aFamilyName);
- }
- strCellsOut<<ends;
- strTypesOut<<ends;
- strOut<<"CELLS "<<aNbCells<<"\t"<<aCellsSize<<endl;
- auto_ptr<char> aRet(strCellsOut.str());
- strOut<<aRet.get()<<endl;
- strOut<<"CELL_TYPES "<<aNbCells<<endl;
- aRet.reset(strTypesOut.str());
- strOut<<aRet.get()<<endl;
- strOut<<ends;
- aReader.reset(OutputType::New());
- //aReader = OutputType::New();
- aReader->ReadFromInputStringOn();
- aRet.reset(strOut.str());
- aReader->SetInputString(aRet.get());
- if(MYDEBUGWITHFILES){
- string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
- string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1();
- string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-";
- aFileName += aMeshName + "-" + aGroupName + "-Conv.vtk";
- ofstream stmOut(aFileName.c_str(),ios::out);
- stmOut<<aRet.get();
- }
- }
- return aReader.get();
- //return aReader;
-}
-
-VISU_Convertor::OutputType* VISU_Convertor_impl::GetFieldOnMesh(const string& theMeshName,
- const VISU::TEntity& theEntity,
- const string& theFieldName,
- int theStampsNum)
- throw(std::runtime_error&)
-{
- if(!myIsDone) { myIsDone = true; Build();}
- if(MYDEBUG){
- MESSAGE("GetFieldOnMesh - theMeshName = '"<<theMeshName<<"; theEntity = "<<theEntity);
- MESSAGE("GetFieldOnMesh - theFieldName = '"<<theFieldName<<"'; theStampsNum = "<<theStampsNum);
- }
- //Cheching possibility do the query
- if(myMeshMap.find(theMeshName) == myMeshMap.end())
- throw std::runtime_error("GetFieldOnMesh >> There is no mesh with the name!!!");
- VISU::TMesh& aMesh = myMeshMap[theMeshName];
- VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- if(aMeshOnEntityMap.find(theEntity) == aMeshOnEntityMap.end())
- throw std::runtime_error("GetFieldOnMesh >> There is no mesh on the entity!!!");
- VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMap[theEntity];
- VISU::TMeshOnEntity* pVtkMeshOnEntity = &aMeshOnEntity;
- if(theEntity == VISU::NODE_ENTITY){
- if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) == aMeshOnEntityMap.end())
- throw std::runtime_error("GetFieldOnMesh >> There is no mesh on CELL_ENTITY!!!");
- pVtkMeshOnEntity = &aMeshOnEntityMap[VISU::CELL_ENTITY];
- }
- VISU::TMeshOnEntity& aVtkMeshOnEntity = *pVtkMeshOnEntity;
- VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
- if(aFieldMap.find(theFieldName) == aFieldMap.end())
- throw std::runtime_error("GetFieldOnMesh >> There is no field on the mesh!!!");
- VISU::TField& aField = aFieldMap[theFieldName];
- VISU::TField::TValField& aValField = aField.myValField;
- if(aValField.find(theStampsNum) == aValField.end())
- throw std::runtime_error("GetFieldOnMesh >> There is no field with the timestamp!!!");
- VISU::TField::TValForTime& aValForTime = aValField[theStampsNum];
- VISU::TVTKReader& aReader = aValForTime.myStorage;
- //Main part of code
- if(aReader.get() == NULL){
- LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime);
- try{
- LoadMeshOnEntity(aVtkMeshOnEntity);
- }catch(std::runtime_error& exc){
- aVtkMeshOnEntity = aMeshOnEntity;
- MESSAGE("Follow exception was accured :\n"<<exc.what());
- }catch(...){
- aVtkMeshOnEntity = aMeshOnEntity;
- MESSAGE("Unknown exception was accured!");
- }
- ostrstream strOut;
- strOut<<GetHead(theMeshName + dtos("-%d-",theEntity) + theFieldName + dtos("-%d",theStampsNum));
- strOut<<GetPoints(aMesh);
- pair<int,int> aCellsDim = aVtkMeshOnEntity.GetCellsDims();
- int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second;
- ostrstream strCellsOut, strTypesOut;
- GetCells(strCellsOut,strTypesOut,aVtkMeshOnEntity);
- strCellsOut<<ends;
- strTypesOut<<ends;
- strOut<<"CELLS "<<aNbCells<<"\t"<<aCellsSize<<endl;
- auto_ptr<char> aRet(strCellsOut.str());
- strOut<<aRet.get()<<endl;
- strOut<<"CELL_TYPES "<<aNbCells<<endl;
- aRet.reset(strTypesOut.str());
- strOut<<aRet.get()<<endl;
- int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
- strOut<<GetField(aField,aValForTime,aMesh.myDim,aNbPoints,aNbCells);
- strOut<<ends;
- aReader.reset(OutputType::New());
- //aReader = OutputType::New();
- aReader->ReadFromInputStringOn();
- aRet.reset(strOut.str());
- aReader->SetInputString(aRet.get());
- if(MYDEBUGWITHFILES){
- string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
- string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1();
- string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-";
- aFileName += aMeshName + dtos("-%d-",theEntity) + aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk";
- ofstream stmOut(aFileName.c_str(),ios::out);
- stmOut<<aRet.get();
- }
- }
- return aReader.get();
- //return aReader;
-}
-
-inline void PrintCells(ostrstream& strCellsOut, const VISU::TMeshOnEntity::TConnect& theVector,
- ostrstream& strTypesOut, const int theVtkType)
-{
- strTypesOut<<theVtkType<<"\n";
- int kEnd = theVector.size();
- strCellsOut<<kEnd<<"\t";
- for(int k = 0; k < kEnd; k++)
- strCellsOut<<theVector[k]<<"\t";
- strCellsOut<<endl;
-}
-
-int VISU_Convertor_impl::GetCells(ostrstream& strCellsOut, ostrstream& strTypesOut,
- const VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName) const
- throw (std::runtime_error&)
-{
- //Check on existing family
- const VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
- bool isFamilyPresent = (pFamily != NULL);
- const VISU::TFamily& aFamily = *pFamily;
- //Main part of code
- if(MYDEBUG) MESSAGE("GetCells - isFamilyPresent = "<<isFamilyPresent);
- const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn;
- VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin();
- for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){
- const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second;
- int aVtkType = aCellsConnIter->first;
- if(MYDEBUG) MESSAGE("GetCells - aVtkType = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
- if(!isFamilyPresent)
- for(int j = 0, jEnd = anArray.size(); j < jEnd; j++)
- PrintCells(strCellsOut,anArray[j],strTypesOut,aVtkType);
- else{
- const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
- if(aSubMesh.empty()) throw std::runtime_error("GetCells >> There is no elements on the family !!!");
- VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType);
- if(aSubMeshIter == aSubMesh.end()) continue;
- const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
- if(MYDEBUG) MESSAGE("GetCells - aSubMeshOnCellType.size() = "<<aSubMeshOnCellType.size());
- VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
- for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++)
- PrintCells(strCellsOut,anArray[*aSubMeshOnCellTypeIter],strTypesOut,aVtkType);
- }
- }
- return 1;
-}
-
-string VISU_Convertor_impl::GetHead(const string& theMeshName) const throw (std::runtime_error&){
- ostrstream strOut;
- strOut<<"# vtk DataFile Version 3.2\n";
- strOut<<theMeshName<<endl;
- strOut<<"ASCII\n";
- strOut<<"DATASET UNSTRUCTURED_GRID\n";
- strOut<<ends;
- auto_ptr<char> aRet(strOut.str());
- return aRet.get();
-}
-
-string VISU_Convertor_impl::GetPoints(const VISU::TMesh& theMesh) const
- throw (std::runtime_error&)
-{
- ostrstream strOut;
- strOut.setf(ios::scientific,ios::floatfield); strOut.precision(PRECISION);
- const VISU::TMesh::TPointsCoord& anArray = theMesh.myPointsCoord;
- int iEnd = theMesh.myPointsCoord.size();
- int aNbPoints = iEnd/theMesh.myDim;
- strOut<<"POINTS "<<aNbPoints<<" float\n";
- if(MYDEBUG)
- MESSAGE("GetPoints - aNbPoints = "<<aNbPoints<<"; myDim = "<<theMesh.myDim);
- switch(theMesh.myDim) {
- case 1:
- for (int i = 0; i < iEnd;)
- strOut<<anArray[i++]<<"\n";
- break;
- case 2:
- for (int i = 0; i < iEnd;){
- strOut<<anArray[i++]<<"\t";
- strOut<<anArray[i++]<<"\t";
- strOut<<0.0<<"\n";
- }
- break;
- case 3:
- for (int i = 0; i < iEnd;){
- strOut<<anArray[i++]<<"\t";
- strOut<<anArray[i++]<<"\t";
- strOut<<anArray[i++]<<"\n";
- }
- break;
- }
- strOut<<ends;
- auto_ptr<char> aRet(strOut.str());
- return aRet.get();
-}
-
-string VISU_Convertor_impl::GetField(const VISU::TField& theField,
- const VISU::TField::TValForTime& theValForTime,
- int theDim, int theNbPoints, int theNbCells) const
- throw (std::runtime_error&)
-{
- ostrstream strOut;
- strOut.setf(ios::scientific,ios::floatfield); strOut.precision(PRECISION);
- string aName = GenerateName(theField.myName,theValForTime.myId);
- if(MYDEBUG) MESSAGE("GetField - aTime = "<<theValForTime.myId<<"; aName = "<<aName);
- switch(theField.myEntity) {
- case VISU::NODE_ENTITY :
- strOut<<"POINT_DATA "<<theNbPoints<<"\n";
- break;
- default:
- strOut<<"CELL_DATA "<<theNbCells<<"\n";
- }
- switch(theField.myNbComp) {
- case 1:
- strOut<<"SCALARS "<<aName<<" float\n";
- strOut<<"LOOKUP_TABLE default\n";
- break;
- default:
- strOut<<"VECTORS "<<aName<<" float\n";
- break;
- }
- const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells;
- VISU::TField::TValForCells::const_iterator aValForCellsIter = aValForCells.begin();
- for(; aValForCellsIter != aValForCells.end(); aValForCellsIter++) {
- const VISU::TField::TValForCellsWithType& anArray = aValForCellsIter->second;
- int iEnd = anArray.size()/theField.myNbComp;
- int aVtkType = aValForCellsIter->first;
- if(MYDEBUG) MESSAGE("GetField - iEnd = "<<iEnd<<"; aVtkType = "<<aVtkType<<"; theDim = "<<theDim);
- if(theField.myNbComp == 1){
- for (int i = 0; i < iEnd;) strOut<<anArray[i++]<<"\n";
- }else if(theDim == 2){
- for (int i = 0, ji = 0; i < iEnd; ji = (++i)*theField.myNbComp){
- strOut<<anArray[ji++]<<"\t";
- strOut<<anArray[ji++]<<"\t";
- strOut<<0.0<<"\n";
- }
- }else if(theDim == 3){
- for (int i = 0, ji = 0; i < iEnd; ji = (++i)*theField.myNbComp){
- strOut<<anArray[ji++]<<"\t";
- strOut<<anArray[ji++]<<"\t";
- strOut<<anArray[ji++]<<"\n";
- }
- }else
- throw std::runtime_error("GetField - There is algorithm for representation the field !!!");
- }
- strOut<<ends;
- auto_ptr<char> aRet(strOut.str());
- return aRet.get();
-}
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Convertor_impl.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_Convertor_impl_HeaderFile
-#define VISU_Convertor_impl_HeaderFile
-
-#include "VISU_Convertor.hxx"
-
-extern "C"{
-#include <med.h>
-}
-
-#include <qstring.h>
-#include <qfileinfo.h>
-
-#include <fstream>
-#include <strstream>
-using namespace std;
-
-class VISU_Convertor_impl: public VISU_Convertor{
- private:
- string GetHead(const string& theMeshName) const throw (std::runtime_error&);
- string GetPoints(const VISU::TMesh& theMesh) const throw (std::runtime_error&);
- int GetCells(ostrstream& strCellsOut, ostrstream& strTypesOut,
- const VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName = "") const throw (std::runtime_error&);
- string GetField(const VISU::TField& theField,
- const VISU::TField::TValForTime& theValForTime,
- int theDim, int theNbPoints, int theNbCells) const
- throw (std::runtime_error&);
- public:
- VISU_Convertor_impl();
- virtual ~VISU_Convertor_impl();
- virtual VISU_Convertor* Build() throw (std::runtime_error&) { return this;};
- virtual OutputType* GetMeshOnEntity(const string& theMeshName,
- const VISU::TEntity& theEntity,
- const string& theFamilyName = "")
- throw(std::runtime_error&);
- virtual OutputType* GetMeshOnGroup(const string& theMeshName,
- const string& theGroupName)
- throw(std::runtime_error&);
- virtual OutputType* GetFieldOnMesh(const string& theMeshName,
- const VISU::TEntity& theEntity,
- const string& theFieldName,
- int theStampsNum)
- throw(std::runtime_error&);
-
- protected:
- virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName = "")
- throw (std::runtime_error&) = 0;
- virtual int LoadMeshOnGroup(VISU::TMesh& theMesh,
- const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
- throw (std::runtime_error&) = 0;
- virtual int LoadFieldOnMesh(VISU::TMesh& theMesh,
- VISU::TMeshOnEntity& theMeshOnEntity,
- VISU::TField& theField,
- VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&) = 0;
-};
-
-extern "C"{
- int getNbMedConnect(int theMedType, int theMedEntity, int theMeshDim);
- int getNbMedNodes(int theMedType);
- int med2vtkCellType(int theMedType);
- int vtk2medCellType(int theVtkType);
- int getIdMedType(int medType);
-}
-
-struct Med2vtk {
- med_geometrie_element medType;
- const char *medName;
- int medNbNodes;
- int vtkType;
- const char *vtkName;
- int vtkNbNodes;
-};
-extern Med2vtk med2vtk[MED_NBR_GEOMETRIE_MAILLE];
-#endif
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_DatConvertor.cxx
-// Author : Alexey PETROV
-// Module : VISU
-
-using namespace std;
-#include "VISU_DatConvertor.hxx"
-using namespace std;
-
-#ifdef DEBUG
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 0;
-#endif
-static int PRECISION = 7;
-
-extern "C"
-VISU_Convertor* CreateDatConvertor(const string& theFileName) throw(std::runtime_error&){
- VISU_DatConvertor* aConvertor = new VISU_DatConvertor(theFileName);
- aConvertor->Build();
- return aConvertor;
-}
-VISU_DatConvertor::VISU_DatConvertor(const string& theFileName) throw(std::runtime_error&){
- myFileInfo.setFile(QString(theFileName.c_str()));
- myName = (const char*)(myFileInfo.baseName());
-}
-
-VISU_Convertor* VISU_DatConvertor::Build() throw (std::runtime_error&){
- /*
- ifstream stmIn(myFileInfo.absFilePath());
- if(!stmIn.good())
- throw std::runtime_error(string("VISU_DatConvertor::CreateResult() >> can't open file - ") +
- (const char*)myFileInfo.absFilePath());
- int aNbPoints, aNbCells, aNbFields;
- ImportHead(&stmIn,&aNbPoints,&aNbCells,&aNbFields);
- ImportPoints(&stmIn,aNbPoints);
- vector<int> aCellsType(aNbCells);
- ImportCells(&stmIn,&aCellsType);
- for(int i = 0; i < aNbFields; i++)
- ImportField(&stmIn,aNbPoints,&aCellsType);
- myIsDone = true;
- */
- return this;
-}
-
-int VISU_DatConvertor::ImportField(ifstream* pStmIn, int theNbPoints, vector<int>* pCellsType)
- throw (std::runtime_error&)
-{
- /*
- ifstream &stmIn = *pStmIn;
- vector<int>& aCellsType = *pCellsType;
- int aNbCells = aCellsType.size();
- string aName; stmIn>>aName; stmIn>>aName;
- VISU::TMesh& aMesh = myMeshMap[myName];
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY];
- VISU::TField& aField = aMeshOnEntity.myFieldMap[aName];
- aField.myMeshName = myName;
- stmIn>>(aField.myNbComp);
- aField.myNbComp %= 100;
- int iEnd; stmIn>>iEnd;
- if(iEnd == theNbPoints)
- aField.myEntity = VISU::NODE_ENTITY;
- else if(iEnd == aNbCells)
- aField.myEntity = VISU::CELL_ENTITY;
- else
- throw std::runtime_error("ImportChamp >> elements doesn't connected to points or cells");
- if(MYDEBUG)
- MESSAGE("FieldInfo - myMeshName = "<<aField.myMeshName<<"; myNbComp = "<<aField.myNbComp);
- for(int i = 0, tmp; i < iEnd; i++) {
- stmIn>>tmp;
- VISU::TField::TTime aTime(0.0,"");
- VISU::TField::TValForCellsWithType &anArray = aField.myValField[aTime][aCellsType[i]];
- for(int j = 0; j < aField.myNbComp; j++){
- float tmp; stmIn>>tmp;
- anArray.push_back(tmp);
- }
- }
- */
- return 0;
-}
-
-int VISU_DatConvertor::ImportHead(ifstream* pStmIn, int* theNbPoints,
- int* theNbCells, int* theNbFields)
- throw (std::runtime_error&)
-{
- /*
- ifstream &stmIn = *pStmIn;
- const int BUFSIZE = 256;
- char buf[BUFSIZE];
- stmIn.getline(buf,BUFSIZE);
- istrstream strIn(buf);
- VISU::TMesh& aMesh = myMeshMap[myName];
- *theNbFields = 0;
- strIn>>(*theNbPoints); strIn>>(*theNbCells); strIn>>(*theNbFields);
- if(MYDEBUG)
- MESSAGE("ImportHead - theNbPoints = "<<(*theNbPoints)<<
- "; theNbCells = "<<(*theNbCells)<<
- "; theNbFields = "<<(*theNbFields));
- */
- return 0;
-}
-
-int VISU_DatConvertor::ImportPoints(ifstream* pStmIn, int theNbPoints)
- throw (std::runtime_error&)
-{
- /*
- ifstream &stmIn = *pStmIn;
- VISU::TMesh& aMesh = myMeshMap[myName];
- aMesh.myName = myName;
- aMesh.myDim = 3;
- int iEnd = aMesh.myDim*theNbPoints;
- if(MYDEBUG) MESSAGE("ImportPoints - iEnd = "<<iEnd);
- vector<float> &aPointsCoord = aMesh.myPointsCoord;
- aPointsCoord.resize(iEnd);
- for(int i = 0, tmp; i < iEnd;){
- stmIn>>tmp;
- stmIn>>aPointsCoord[i++]; stmIn>>aPointsCoord[i++]; stmIn>>aPointsCoord[i++];
- }
- */
- return 0;
-}
-
-int VISU_DatConvertor::ImportCells(ifstream* pStmIn, vector<int>* pCellsType)
- throw (std::runtime_error&)
-{
- /*
- ifstream &stmIn = *pStmIn;
- vector<int>& aCellsType = *pCellsType;
- int aNbCells = aCellsType.size();
- if(MYDEBUG) MESSAGE("ImportCells - theNbCells - Beginning");
- VISU::TMesh& aMesh = myMeshMap[myName];
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY];
- aMeshOnEntity.myEntity = VISU::CELL_ENTITY;
- aMeshOnEntity.myMeshName = myName;
- for(int i = 0, aMedType, aVtkType; i < aNbCells; i++){
- stmIn>>aMedType; stmIn>>aMedType;
- aCellsType[i] = aVtkType = med2vtkCellType(aMedType);
- VISU::TMeshOnEntity::TConnForCellType& anArray = aMeshOnEntity.myCellsConn[aVtkType];
- anArray.push_back(VISU::TMeshOnEntity::TConnect());
- VISU::TMeshOnEntity::TConnect& aVector = anArray.back();
- int jEnd = getNbMedNodes(aMedType);
- aVector.resize(jEnd);
- for(int j = 0, tmp; j < jEnd; j++){
- stmIn>>tmp;
- aVector[j] = tmp - 1;
- }
- }
- if(MYDEBUG) MESSAGE("ImportCells - theNbCells - End");
- */
- return 0;
-}
-
-/*
-int VISU_Convertor_impl::ToDatFile(const string& theFileName) throw(std::runtime_error&){
- if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - "<<theFileName);
- if(!myIsDone && Build() != NULL) myIsDone = true;
- ofstream stmOut(theFileName.c_str(),ios::out);
- stmOut.precision(PRECISION);
- stmOut.setf(ios::scientific,ios::floatfield);
-
- VISU::TMeshMap::const_iterator aMeshIter = myMeshMap.begin();
- if(aMeshIter != myMeshMap.end()){
- const VISU::TMesh &aMesh = aMeshIter->second;
- if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - aMeshName = "<<aMeshIter->first);
- VISU::TFieldMap aFieldMap = GetFieldMapForMesh(aMeshIter->first);
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(VISU::CELL_ENTITY);
- if(aMeshOnEntityMapIter != aMeshOnEntityMap.end()){
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
- int aNbCells = aMeshOnEntity.GetCellsDims().first;
- stmOut<<aNbPoints<<"\t"<<aNbCells<<"\t"<<aFieldMap.size()<<endl;
- if(MYDEBUG)
- MESSAGE("VISU_Convertor_impl::ToDatFile - aNbPoints = "<<aNbPoints<<
- "; aNbCells = "<<aNbCells<<"; aNbFields = "<<aFieldMap.size());
- for(int i = 0, j = 0; i < aNbPoints; i++, j = 3*i){
- stmOut<<(i+1)<<"\t";
- stmOut<<aMesh.myPointsCoord[j]<<"\t";
- stmOut<<aMesh.myPointsCoord[j+1]<<"\t";
- stmOut<<aMesh.myPointsCoord[j+2]<<endl;
- }
- const VISU::TMeshOnEntity::TCellsConn &aCellsConn = aMeshOnEntity.myCellsConn;
- VISU::TMeshOnEntity::TCellsConn::const_iterator iter = aCellsConn.begin();
- for(int i = 0; iter != aCellsConn.end(); iter++){
- if(MYDEBUG)
- MESSAGE("VISU_Convertor_impl::ToDatFile - vtkCellType = "<<iter->first);
- const VISU::TMeshOnEntity::TConnForCellType& anArray = iter->second;
- for(int j = 0, jEnd = anArray.size(); j < jEnd; j++){
- stmOut<<(++i)<<"\t";
- stmOut<<vtk2medCellType(iter->first)<<"\t";
- const vector<int>& aVector = anArray[j];
- int kEnd = aVector.size();
- for(int k = 0; k < kEnd; k++)
- stmOut<<aVector[k]<<"\t";
- stmOut<<endl;
- }
- }
- if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - Beginning of Field Conversion");
- VISU::TFieldMap::const_iterator aFieldIter = aFieldMap.begin();
- for(int i = 0; aFieldIter != aFieldMap.end(); aFieldIter++){
- const VISU::TField &aField = aFieldIter->second;
- const VISU::TField::TValField &aValField = aField.myValField;
- VISU::TField::TValField::const_reverse_iterator iter = aField.myValField.rbegin();
- for(int i = 0; iter != aValField.rend(); iter++, i++) {
- if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - aTime = "<<i);
- const VISU::TField::TValForTime& aValForTime = iter->second;
- VISU::TField::TValForTime::const_iterator jter = aValForTime.begin();
- stmOut<<(++i)<<endl;
- int prefix = (aField.myEntity == VISU::CELL_ENTITY? 100: 200);
- int jEnd = (aField.myEntity == VISU::CELL_ENTITY? aNbCells: aNbPoints);
- string aName = GenerateName((aFieldIter->first).c_str(),i);
- stmOut<<aName<<endl;
- stmOut<<(prefix + aField.myNbComp)<<"\t"<<jEnd<<endl;
- if(MYDEBUG)
- MESSAGE("VISU_Convertor_impl::ToDatFile - aName = "<<aName<<"; jEnd = "<<jEnd);
- for(int j = 0; jter != aValForTime.end(); jter++) {
- const VISU::TField::TValForCellsWithType& anArray = jter->second;
- int kEnd = anArray.size(), aVtkType = jter->first;
- switch(aField.myNbComp) {
- case 1:
- for (int k = 0; k < kEnd;) {
- stmOut<<(++j)<<"\t";
- stmOut<<anArray[k++]<<"\n";
- }
- break;
- case 2:
- for (int k = 0; k < kEnd;){
- stmOut<<(++j)<<"\t";
- stmOut<<anArray[k++]<<"\t";
- stmOut<<anArray[k++]<<"\t";
- stmOut<<0.0<<"\n";
- }
- break;
- case 3:
- for (int k = 0; k < kEnd;){
- stmOut<<(++j)<<"\t";
- stmOut<<anArray[k++]<<"\t";
- stmOut<<anArray[k++]<<"\t";
- stmOut<<anArray[k++]<<"\n";
- }
- break;
- }
- }
- }
- }
- }
- }
- return 1;
-}
-*/
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_DatConvertor.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_DatConvertor_HeaderFile
-#define VISU_DatConvertor_HeaderFile
-
-#include "VISU_Convertor_impl.hxx"
-#include <fstream>
-
-class VISU_DatConvertor: public VISU_Convertor_impl{
- VISU_DatConvertor();
- VISU_DatConvertor(const VISU_DatConvertor&);
-public:
- VISU_DatConvertor(const string& theFileName) throw (std::runtime_error&);
- virtual VISU_Convertor* Build() throw (std::runtime_error&);
-protected:
- QFileInfo myFileInfo;
- int ImportHead(ifstream* pStmIn, int* theNbPoints, int* theNbCells, int* theNbFields)
- throw (std::runtime_error&);
- int ImportPoints(ifstream*, int theNbPoints)
- throw (std::runtime_error&);
- int ImportCells(ifstream*, vector<int>* aCellsType)
- throw (std::runtime_error&);
- int ImportField(ifstream*, int theNbPoints, vector<int>* aCellsType)
- throw (std::runtime_error&);
- protected:
- virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName = "")
- throw (std::runtime_error&) {return 1;}
- virtual int LoadMeshOnGroup(VISU::TMesh& theMesh,
- const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
- throw (std::runtime_error&) {return 1;}
- virtual int LoadFieldOnMesh(VISU::TMesh& theMesh,
- VISU::TMeshOnEntity& theMeshOnEntity,
- VISU::TField& theField,
- VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&) {return 1;}
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Extractor.cxx
-// Module : VISU
-
-using namespace std;
-#include "VISU_Extractor.hxx"
-
-#include <vtkUnstructuredGridReader.h>
-
-#ifdef DEBUG
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 0;
-#endif
-
-VISU_Extractor::VISU_Extractor(){
- myNbComp = 0;
- myScalarMode = 0;
-}
-VISU_Extractor::~VISU_Extractor() {}
-VISU_Extractor* VISU_Extractor::New(){
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_Extractor");
- if(ret) return (VISU_Extractor*)ret;
- return new VISU_Extractor;
-}
-void VISU_Extractor::Extract(vtkUnstructuredGridReader* theReader,
- const string& theFieldName, int theScalarMode,
- int theNbComp, const VISU::TEntity& theEntity)
-{
- myScalarMode = theScalarMode;
- myNbComp = theNbComp;
- myEntity = theEntity;
- if(myNbComp == 1)
- theReader->SetScalarsName(theFieldName.c_str());
- else
- theReader->SetVectorsName(theFieldName.c_str());
- SetInput((vtkDataSet*)(theReader->GetOutput()));
- Modified();
- Update();
-}
-template<typename TypeData> void
-execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){
-// mpv porting vtk 4.2.2
-// vtkVectors *inVectors = theInputData->GetVectors();
- vtkDataArray *inVectors = theInputData->GetVectors();
- if ( !inVectors || theNbComp < 1 )
- return;
-// mpv porting vtk 4.2.2
-// vtkScalars *newScalars = vtkScalars::New();
- vtkFloatArray *newScalars = vtkFloatArray::New();
- newScalars->SetNumberOfComponents(1);
- newScalars->SetNumberOfTuples(theNbComp);
- for (int ptId = 0; ptId < theNbComp; ptId++) {
- float v[3], s;
- inVectors->GetTuple(ptId,v);
- if ( theScalarMode < 1 || theScalarMode > 3)
- s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
- else
- s = v[theScalarMode - 1];
- newScalars->SetTuple1(ptId, s);
- }
- theOutputData->SetScalars(newScalars);
- newScalars->Delete();
-}
-void VISU_Extractor::Execute(){
- vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
- output->CopyStructure(input);
- output->GetPointData()->CopyAllOff();
- output->GetCellData()->CopyAllOff();
- if(myEntity == VISU::NODE_ENTITY){
- output->GetPointData()->CopyVectorsOn();
- int nbComp = input->GetNumberOfPoints();
- vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
- if(myNbComp > 1)
- execute(nbComp,myScalarMode,inData,outData);
- else
- output->GetPointData()->CopyScalarsOn();
- outData->PassData(inData);
- }else{
- output->GetCellData()->CopyVectorsOn();
- int nbComp = input->GetNumberOfCells();
- vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
- if(myNbComp > 1)
- execute(nbComp,myScalarMode,inData,outData);
- else
- output->GetCellData()->CopyScalarsOn();
- outData->PassData(inData);
- }
-}
-
-
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Extractor.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_Extractor_HeaderFile
-#define VISU_Extractor_HeaderFile
-
-#include "VTKViewer_Common.h"
-#include <vtkDataSetToDataSetFilter.h>
-#include "VISU_Convertor.hxx"
-class vtkUnstructuredGridReader;
-
-class VTK_EXPORT VISU_Extractor : public vtkDataSetToDataSetFilter{
-public:
- vtkTypeMacro(VISU_Extractor,vtkDataSetToDataSetFilter);
- static VISU_Extractor *New();
- void Extract(vtkUnstructuredGridReader* theReader,
- const string& theFieldName, int theScalarMode,
- int theNbComp, const VISU::TEntity& theEntity);
-protected:
- VISU_Extractor();
- virtual ~VISU_Extractor();
- VISU_Extractor(const VISU_Extractor&) {};
- void operator=(const VISU_Extractor&) {};
- void Execute();
-
- int myNbComp;
- int myScalarMode;
- VISU::TEntity myEntity;
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_FieldTransform.cxx
-// Module : VISU
-
-using namespace std;
-#include "VISU_FieldTransform.hxx"
-#include "utilities.h"
-
-#include <vtkUnstructuredGridReader.h>
-
-#ifdef DEBUG
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
-extern "C" {
-double Identical(double theArg) {
- return theArg;
-}
-
-double Logarithmic10(double theArg) {
- if(theArg <= 0.0) return -1.0E+38;
- //if(theArg == 0.0) return 0.0;
- //if(theArg < 0.0) return log10(-theArg);
- return log10(theArg);
-}
-
-}
-
-VISU_FieldTransform::VISU_FieldTransform(){
- myFunction = &Identical;
-}
-
-VISU_FieldTransform::~VISU_FieldTransform() {}
-
-VISU_FieldTransform* VISU_FieldTransform::New(){
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_FieldTransform");
- if(ret) return (VISU_FieldTransform*)ret;
- return new VISU_FieldTransform;
-}
-
-void VISU_FieldTransform::SetTransformFunction(TTransformFun theFunction) {
- myFunction = theFunction;
- if(myFunction == NULL) myFunction = &Identical;
- Modified();
-}
-
-void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) {
- myScalarRange[0] = theScalarRange[0];
- myScalarRange[1] = theScalarRange[1];
- Modified();
-}
-
-template<typename TypeData> void
-ExecVectors(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange[2],
- int theNbComponent, TypeData* theInputData, TypeData* theOutputData)
-{
- vtkDataArray *inVectors = theInputData->GetVectors();
- if ( !inVectors || theNbComponent < 1 ) return;
- vtkFloatArray *newVectors = vtkFloatArray::New();
- newVectors->SetNumberOfComponents(3);
- newVectors->SetNumberOfTuples(theNbComponent);
- float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])};
- float *V, v[3], vMag, aDelta = aScalarRange[1] - aScalarRange[0];
- for (int ptId = 0; ptId < theNbComponent; ptId++) {
- V = inVectors->GetTuple3(ptId);
- vMag = vtkMath::Norm(V);
- vMag = ((*theFunction)(vMag) - aScalarRange[0]) / aDelta * theScalarRange[1] / vMag;
- if(vMag <= 0.0) vMag = 0.0;
- v[0] = V[0]*vMag;
- v[1] = V[1]*vMag;
- v[2] = V[2]*vMag;
- newVectors->SetTuple3(ptId, v[0], v[1], v[2]);
- }
- theOutputData->SetVectors(newVectors);
- newVectors->Delete();
-}
-
-template<typename TypeData> void
-ExecScalars(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange[2],
- int theNbComponent, TypeData* theInputData, TypeData* theOutputData)
-{
- vtkDataArray *inScalars = theInputData->GetScalars();
- if ( !inScalars || theNbComponent < 1 )
- return;
- vtkFloatArray *newScalars = vtkFloatArray::New();
- newScalars->SetNumberOfComponents(1);
- newScalars->SetNumberOfTuples(theNbComponent);
- float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])};
- for (int ptId = 0; ptId < theNbComponent; ptId++) {
- float s = (*theFunction)(inScalars->GetTuple1(ptId ));
- if(s < aScalarRange[0]) s = aScalarRange[0];
- newScalars->SetTuple1(ptId, s);
- }
- theOutputData->SetScalars(newScalars);
- newScalars->Delete();
-}
-
-void VISU_FieldTransform::Execute(){
- vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
- output->CopyStructure(input);
- if(myFunction != &Identical){
- output->GetPointData()->CopyAllOff();
- output->GetCellData()->CopyAllOff();
-
- ExecScalars(myFunction,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData());
- ExecVectors(myFunction,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData());
-
- ExecScalars(myFunction,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData());
- ExecVectors(myFunction,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData());
- }else{
- output->GetPointData()->CopyAllOn();
- output->GetCellData()->CopyAllOn();
-
- output->GetPointData()->PassData(input->GetPointData());
- output->GetCellData()->PassData(input->GetCellData());
- }
-}
-
-
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_Extractor.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_FieldTransform_HeaderFile
-#define VISU_FieldTransform_HeaderFile
-
-#include "VTKViewer_Common.h"
-#include <vtkDataSetToDataSetFilter.h>
-
-class VTK_EXPORT VISU_FieldTransform : public vtkDataSetToDataSetFilter{
-public:
- vtkTypeMacro(VISU_FieldTransform,vtkDataSetToDataSetFilter);
- static VISU_FieldTransform *New();
- typedef double (*TTransformFun)(double);
- void SetTransformFunction(TTransformFun theFunction);
- void SetScalarRange(float theScalarRange[2]);
-protected:
- VISU_FieldTransform();
- virtual ~VISU_FieldTransform();
- VISU_FieldTransform(const VISU_FieldTransform&) {};
- void operator=(const VISU_FieldTransform&) {};
- void Execute();
-
- TTransformFun myFunction;
- float myScalarRange[2];
-};
-extern "C" {
- double Identical(double theArg);
- double Logarithmic10(double theArg);
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_MedConvertor.cxx
-// Author : Alexey PETROV
-// Module : VISU
-
-using namespace std;
-#include "VISU_MedConvertor.hxx"
-#include <valarray>
-#include <vtkCellType.h>
-#define USER_INTERLACE MED_FULL_INTERLACE
-using namespace std;
-
-#ifdef DEBUG
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-static med_err ret = 0;
-
-typedef map<VISU::TEntity,med_entite_maillage> TVisu2MedEntity;
-static TVisu2MedEntity aVisu2MedEntity;
-static int INIT = (
- aVisu2MedEntity[VISU::NODE_ENTITY] = MED_NOEUD,
- aVisu2MedEntity[VISU::EDGE_ENTITY] = MED_ARETE,
- aVisu2MedEntity[VISU::FACE_ENTITY] = MED_FACE,
- aVisu2MedEntity[VISU::CELL_ENTITY] = MED_MAILLE,
- 1);
-
-static med_geometrie_element NODEGEOM[1] = {MED_POINT1};
-static med_geometrie_element EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
- MED_SEG2, MED_SEG3
- };
-static med_geometrie_element FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
- MED_TRIA3, MED_QUAD4, MED_TRIA6, MED_QUAD8
- };
-static med_geometrie_element CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
- MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3,
- MED_QUAD4, MED_TRIA6, MED_QUAD8, MED_TETRA4,
- MED_PYRA5, MED_PENTA6, MED_HEXA8, MED_TETRA10,
- MED_PYRA13, MED_PENTA15, MED_HEXA20
- };
-void GetEntity2Geom(const VISU::TEntity& theEntity, med_geometrie_element*& theVector, int* theEnd)
- throw (std::runtime_error&)
-{
- switch(theEntity){
- case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
- case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
- case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
- case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
- default:
- throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect");
- }
-}
-
-extern "C"
-VISU_Convertor* CreateMedConvertor(const string& theFileName) throw(std::runtime_error&){
- return new VISU_MedConvertor(theFileName);
-}
-
-int med2vtkCellType(int medType){
- for(int i = 0; i < MED_NBR_GEOMETRIE_MAILLE; i++)
- if(med2vtk[i].medType == medType) return med2vtk[i].vtkType;
- return -1;
-}
-
-int vtk2medCellType(int vtkType){
- for(int i = 0; i < MED_NBR_GEOMETRIE_MAILLE; i++)
- if(med2vtk[i].vtkType == vtkType) return med2vtk[i].medType;
- return -1;
-}
-
-class MedFile{
- char* myFileName;
- med_idt myFid;
- MedFile();
- MedFile(const MedFile&);
-public:
- MedFile(const char* theFileName) throw(std::runtime_error&) :
- myFileName(strdup(theFileName))
- {
- myFid = MEDouvrir(myFileName,MED_LECT);
- if(myFid < 0){
- free(myFileName);
- throw std::runtime_error(string("MedFile::MedFile >> MEDouvrir(...) - ") + theFileName);
- }
- }
- ~MedFile(){
- free(myFileName);
- if(myFid >= 0)
- MEDfermer(myFid);
- }
- const med_idt& GetFid() const { return myFid;};
-};
-
-VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) throw (std::runtime_error&) {
- myFileInfo.setFile(QString(theFileName.c_str()));
- myName = (const char*)(myFileInfo.baseName());
-}
-
-VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) {
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- med_int iMeshEnd = MEDnMaa(fid); //Get number of meshes
- if(MYDEBUG) MESSAGE("ImportInfo - MEDnMaa = "<<iMeshEnd<<"; myFileInfo = "<<myFileInfo.filePath());
- for(int iMesh = 1; iMesh <= iMeshEnd; iMesh++){
- med_int aMeshDim;
- char aMeshName[MED_TAILLE_NOM+1] = "";
- MEDmaaInfo(fid,iMesh,aMeshName,&aMeshDim);
- if(MYDEBUG) MESSAGE("ImportInfo - aMeshName = '"<<aMeshName<<"'; aMeshDim = "<<aMeshDim);
- VISU::TMesh &aMesh = myMeshMap[aMeshName];
- aMesh.myDim = aMeshDim;
- aMesh.myName = aMeshName;
- typedef map<int,VISU::TEntity> TFamily2EntityMap;
- TFamily2EntityMap aFamily2EntityMap;
- TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
- for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) {
- VISU::TEntity anEntity = aVisu2MedEntityIter->first;
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- int medId = getIdMedType(aGeomElemVector[iGeomElem]);
- int aVtkType = med2vtk[medId].vtkType;
- med_geometrie_element aMedType = med2vtk[medId].medType;
- if(aMedEntity == MED_NOEUD){
- med_geometrie_element typgeo = (med_geometrie_element)0;
- med_connectivite typco = (med_connectivite)0;
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_COOR,MED_NOEUD,typgeo,typco);
- if(iNumElemEnd > 0){
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- aMeshOnEntity.myEntity = anEntity;
- aMeshOnEntity.myMeshName = aMeshName;
- if(MYDEBUG)
- MESSAGE("ImportInfo -\t anEntity = "<<anEntity<<"; iNumElemEnd = "<<iNumElemEnd<<
- "; medName = "<<med2vtk[medId].medName<<"; medId = "<<medId);
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- med_repere rep;
- valarray<char> name_coord('\0',aMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<char> unit_coord('\0',aMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<med_float> coord(aMesh.myDim*iNumElemEnd);
- ret = MEDnoeudsLire(fid,aMeshName,aMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep,
- &name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem,
- &num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDnoeudsLire(...)");
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] != 0)
- aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity;
- }
- }
- //Get number of connectivities
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_CONN,aMedEntity,aMedType,MED_NOD);
- if (iNumElemEnd > 0) {
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- aMeshOnEntity.myEntity = anEntity;
- aMeshOnEntity.myMeshName = aMeshName;
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim);
- if(MYDEBUG)
- MESSAGE("ImportInfo -\t anEntity = "<<anEntity<<"; iNumElemEnd = "<<iNumElemEnd<<
- "; medName = "<<med2vtk[medId].medName<<"; aNbConnForElem = "<<aNbConnForElem);
- valarray<med_int> conn(0,aNbConnForElem*iNumElemEnd);
- ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE,
- &name_elem[0],&iname_elem,&num_elem[0],&inum_elem,
- &num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD);
- if (ret < 0) throw std::runtime_error("ImportInfo >> MEDelementsLire(...)");
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] != 0)
- aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity;
- }
- }
- }
- med_int aNbFamily = MEDnFam(fid,aMeshName,0,MED_FAMILLE);
- if(MYDEBUG) MESSAGE("ImportInfo - aNbFamily = "<<aNbFamily);
- for(int aFamInd = 1; aFamInd <= aNbFamily; aFamInd++){
- med_int aNbAttrib = MEDnFam(fid,aMeshName,aFamInd,MED_ATTR);
- valarray<med_int> anAttId(aNbAttrib), anAttVal(aNbAttrib);
- valarray<char> anAttDesc('\0',aNbAttrib*MED_TAILLE_DESC+1);
- med_int aNbGroup = MEDnFam(fid,aMeshName,aFamInd,MED_GROUPE);
- if(0 && MYDEBUG)
- MESSAGE("ImportInfo - aFamInd = "<<aFamInd<<"; aNbAttrib = "<<aNbAttrib<<"; aNbGroup = "<<aNbGroup);
- valarray<char> aGroupNames('\0',aNbGroup*MED_TAILLE_LNOM+1);
- char aFamilyName[MED_TAILLE_NOM+1] = "";
- med_int aFamilyNum;
- ret = MEDfamInfo(fid,aMeshName,aFamInd,aFamilyName,&aFamilyNum,
- &anAttId[0],&anAttVal[0],&anAttDesc[0],&aNbAttrib,
- &aGroupNames[0],&aNbGroup);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDfamInfo");
- if(0 && MYDEBUG)
- MESSAGE("ImportInfo - aFamilyNum = "<<aFamilyNum<<"; aNbGroup = "<<aNbGroup);
- if(aFamily2EntityMap.find(aFamilyNum) == aFamily2EntityMap.end()) {
- if(MYDEBUG) MESSAGE("ImportInfo - a Family with name '"<<aFamilyName<<"' are empty !!!");
- continue;
- }
- VISU::TEntity anEntity = aFamily2EntityMap[aFamilyNum];
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName];
- aFamily.myName = aFamilyName;
- aFamily.myEntity = anEntity;
- aFamily.myId = aFamilyNum;
- if(MYDEBUG)
- MESSAGE("ImportInfo - aFamily.myEntity = "<<anEntity<<
- "; myName = '"<<aFamilyName<<"'; myId = "<<aFamilyNum);
- VISU::TBindGroups& aBindGroups = aFamily.myGroups;
- for(int iGroup = 0, iPos = 0; iGroup < aNbGroup; iGroup++, iPos += MED_TAILLE_LNOM){
- char aGroupName[MED_TAILLE_LNOM+1];
- strncpy(aGroupName,&aGroupNames[iPos],MED_TAILLE_LNOM);
- aGroupName[MED_TAILLE_LNOM] = '\0';
- if(MYDEBUG) MESSAGE("ImportInfo - aGroupName["<<iGroup<<"] = '"<<aGroupName<<"'");
- aBindGroups.insert(aGroupName);
- }
- }
- //Calculation of TMesh.TGroupMap
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- if(aMeshOnEntityMap.empty()) continue;
- VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
- if(aFamilyMap.empty()) continue;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
- for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
- const VISU::TFamily& aFamily = aFamilyMapIter->second;
- const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
- if(aBindGroups.empty()) continue;
- VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
- for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
- const string& aGroupName = *aBindGroupsIter;
- VISU::TGroup& aGroup = aGroupMap[aGroupName];
- aGroup.myName = aGroupName;
- aGroup.myMeshName = aMesh.myName;
- VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
- aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
- }
- }
- }
- //Displaing information for the TMesh.TGroupMap
- VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
- if(MYDEBUG) MESSAGE("ImportInfo - aGroupMap.size() = "<<aGroupMap.size());
- for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
- const string& aGroupName = aGroupMapIter->first;
- if(MYDEBUG) MESSAGE("ImportInfo - aGroupName = '"<<aGroupName<<"' : ");
- const VISU::TGroup& aGroup = aGroupMapIter->second;
- const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup.myFamilyAndEntitySet;
- VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
- for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
- const string& aFamilyName = aFamilyAndEntitySetIter->first;
- if(MYDEBUG) MESSAGE("ImportInfo - \t aFamilyName = '"<<aFamilyName<<"'");
- }
- }
- }
- //Reading information about fields
- med_int iFieldEnd = MEDnChamp(fid,0);
- if (iFieldEnd < 0) throw std::runtime_error("ImportChamps >> MEDnChamp(fid,0)");
- if(MYDEBUG) MESSAGE("ImportInfo - iFieldEnd = "<<iFieldEnd);
- for(med_int iField = 1; iField <= iFieldEnd; iField++){
- med_int ncomp = MEDnChamp(fid,iField);
- if(ncomp < 0) throw std::runtime_error("ImportChamps >> MEDnChamp(fid,i)");
- valarray<char> aCompNames('\0',ncomp*MED_TAILLE_PNOM + 1);
- valarray<char> aUnitNames('\0',ncomp*MED_TAILLE_PNOM + 1);
- char name_field[MED_TAILLE_NOM + 1] = "";
- med_type_champ type_field;
- if(MEDchampInfo(fid,iField,name_field,&type_field,&aCompNames[0],&aUnitNames[0],ncomp) < 0)
- throw std::runtime_error(string("ImportInfo >> MEDchampInfo(...)"));
- //if(type_field != MED_REEL64) continue; //There is some problem in reading INTXX values
- TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
- for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) {
- VISU::TEntity anEntity = aVisu2MedEntityIter->first;
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
- med_int iTimeStampEnd = MEDnPasdetemps(fid,name_field,aMedEntity,aGeom);
- if(iTimeStampEnd < 0) throw std::runtime_error("ImportInfo >> MEDnPasdetemps(...)");
- if(iTimeStampEnd > 0) {
- for(med_int iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++) {
- char aMeshName[MED_TAILLE_NOM+1] = "";
- med_int ngauss = 0, numdt = 0, numo = 0;
- char dt_unit[MED_TAILLE_PNOM+1] = "";
- med_float dt = 0;
- ret = MEDpasdetempsInfo(fid,name_field,aMedEntity,aGeom,iTimeStamp,
- aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...) < 0");
- if(myMeshMap.find(aMeshName) == myMeshMap.end())
- throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...)");
- VISU::TMesh &aMesh = myMeshMap[aMeshName];
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
- VISU::TFieldMap::iterator aFieldMapIter = aMeshOnEntity.myFieldMap.find(name_field);
- //if(MYDEBUG && aFieldMapIter == aMeshOnEntity.myFieldMap.end()){
- VISU::TField& aField = aMeshOnEntity.myFieldMap[name_field];
- if(iTimeStamp == 1){
- if(MYDEBUG){
- MESSAGE("ImportInfo - aField.myName = '"<<name_field<<"'; myNbComp = "<<ncomp);
- MESSAGE("ImportInfo -\t myMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity);
- }
- aField.myId = iField;
- aField.myName = name_field;
- aField.myEntity = anEntity;
- aField.myMeshName = aMeshName;
- aField.myNbComp = ncomp;
- aField.myCompNames.resize(ncomp);
- aField.myUnitNames.resize(ncomp);
- for(int iComp = 0, iPos = 0; iComp < ncomp; iComp++, iPos += MED_TAILLE_PNOM){
- char aCompName[MED_TAILLE_PNOM+1], aUnitName[MED_TAILLE_PNOM+1];
- strncpy(aCompName,&aCompNames[iPos],MED_TAILLE_PNOM);
- aCompName[MED_TAILLE_PNOM] = '\0';
- aField.myCompNames[iComp] = aCompName;
- strncpy(aUnitName,&aUnitNames[iPos],MED_TAILLE_PNOM);
- aUnitName[MED_TAILLE_PNOM] = '\0';
- aField.myUnitNames[iComp] = aUnitName;
- if(MYDEBUG){
- MESSAGE("ImportInfo - aCompName["<<iComp<<"] = '"<<aCompName<<"'");
- MESSAGE("ImportInfo - aUnitName["<<iComp<<"] = '"<<aUnitName<<"'");
- }
- }
-
- }
- VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
- aValForTime.myId = iTimeStamp;
- aValForTime.myTime = VISU::TField::TTime(dt,dt_unit);
- if(MYDEBUG && iGeomElem == 0)
- MESSAGE("ImportInfo -\t aField.myTime = "<<dt<<", "<<dt_unit);
- }
- }
- }
- }
- }
- return this;
-}
-
-int VISU_MedConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName)
- throw (std::runtime_error&)
-{
- //Open the med file (it will be closed by call of destructor)
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- //Main part of code
- const string& aMeshName = theMeshOnEntity.myMeshName;
- const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
- VISU::TMesh& aMesh = myMeshMap[aMeshName];
- int isPointsUpdated;
- if(anEntity == VISU::NODE_ENTITY)
- isPointsUpdated = LoadPoints(fid,aMesh,theFamilyName);
- else
- isPointsUpdated = LoadPoints(fid,aMesh);
- int isCellsOnEntityUpdated = LoadCellsOnEntity(fid,theMeshOnEntity,theFamilyName);
-
- return (isPointsUpdated || isCellsOnEntityUpdated);
-}
-
-int VISU_MedConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh,
- const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
- throw (std::runtime_error&)
-{
- //Open the med file (it will be closed by call of destructor)
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- //Main part of code
- int isPointsUpdated = 0;
- int isCellsOnEntityUpdated = 0;
- VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
- for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
- const string& aFamilyName = aFamilyAndEntitySetIter->first;
- const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
- VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
- if(anEntity == VISU::NODE_ENTITY){
- isPointsUpdated += LoadPoints(fid,theMesh,aFamilyName);
- isCellsOnEntityUpdated += LoadCellsOnEntity(fid,aMeshOnEntity);
- }else{
- isPointsUpdated += LoadPoints(fid,theMesh);
- isCellsOnEntityUpdated += LoadCellsOnEntity(fid,aMeshOnEntity,aFamilyName);
- }
- }
-
- return (isPointsUpdated || isCellsOnEntityUpdated);
-}
-
-int VISU_MedConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh,
- VISU::TMeshOnEntity& theMeshOnEntity,
- VISU::TField& theField,
- VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&)
-{
- //Open the med file (it will be closed by call of destructor)
- MedFile aMedFile(myFileInfo.absFilePath());
- med_idt fid = aMedFile.GetFid();
- //Main part of code
- int isPointsUpdated = LoadPoints(fid,theMesh);
- int isCellsOnEntityUpdated = LoadCellsOnEntity(fid,theMeshOnEntity);
- int isFieldUpdated = LoadField(fid,theMeshOnEntity,theField,theValForTime);
-
- return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
-}
-
-int VISU_MedConvertor::LoadPoints(const med_idt& fid, VISU::TMesh& theMesh, const string& theFamilyName)
- throw (std::runtime_error&)
-{
- try{
- //Check on existing family
- VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY];
- aMeshOnEntity.myEntity = VISU::NODE_ENTITY;
- aMeshOnEntity.myMeshName = theMesh.myName;
- VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName);
- bool isFamilyPresent = (pFamily != NULL);
- VISU::TFamily& aFamily = *pFamily;
- //Check on loading already done
- bool isPointsLoaded = !theMesh.myPointsCoord.empty();
- if(isPointsLoaded)
- if(!isFamilyPresent) return 0;
- else if(!aFamily.mySubMesh.empty()) return 0;
- if(MYDEBUG)
- MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
- //Main part of code
- char aMeshName[MED_TAILLE_NOM+1] = "";
- strcpy(aMeshName,theMesh.myName.c_str());
- med_geometrie_element typgeo = (med_geometrie_element)0; //MED_POINT1
- med_connectivite typco = (med_connectivite)0; //MED_NOD
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_COOR,MED_NOEUD,typgeo,typco);
- if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> MEDnEntMaa(...)");
- if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
- med_repere rep;
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- valarray<char> name_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<char> unit_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1);
- valarray<med_float> coord(theMesh.myDim*iNumElemEnd);
- ret = MEDnoeudsLire(fid,aMeshName,theMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep,
- &name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem,
- &num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd);
- if(ret < 0) throw std::runtime_error("LoadPoints >> MEDnoeudsLire(...)");
- if(!isPointsLoaded){
- VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
- aPointsCoord.resize(iNumElemEnd*theMesh.myDim);
- if(MYDEBUG) MESSAGE("LoadPoints - Filling coordinates of the mesh - inum_elem = "<<inum_elem);
- inum_elem = MED_FAUX; // It is workaround
- if(inum_elem == MED_FAUX)
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
- aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
- else
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
- aPointsCoord[num_elem[iNumElem2Dim]] = coord[iNumElem2Dim];
- if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
- VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
- aConnForCellType.resize(iNumElemEnd);
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- aConnForCellType[iNumElem] = VISU::TMeshOnEntity::TConnect(1,iNumElem);
- }
- if(isFamilyPresent && iNumElemEnd > 0){
- if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
- VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX];
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] == aFamily.myId)
- aSubMeshOnCellType.insert(iNumElem);
- }
- return 1;
- }catch(std::runtime_error& exc){
- theMesh.myPointsCoord.clear();
- throw std::runtime_error(exc.what());
- }catch(...){
- theMesh.myPointsCoord.clear();
- throw std::runtime_error("Unknown exception !!!");
- }
- return 0;
-}
-
-int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName)
- throw (std::runtime_error&)
-{
- try{
- //Check on existing family
- VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
- bool isFamilyPresent = (pFamily != NULL);
- VISU::TFamily& aFamily = *pFamily;
- //Check on loading already done
- bool isCellsLoaded = !theMeshOnEntity.myCellsConn.empty();
- if(isCellsLoaded)
- if(!isFamilyPresent) return 0;
- else if(!aFamily.mySubMesh.empty()) return 0;
- if(MYDEBUG) {
- MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
- MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<isFamilyPresent);
- }
- //Main part of code
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- const med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- char aMeshName[MED_TAILLE_NOM+1] = "";
- strcpy(aMeshName,theMeshOnEntity.myMeshName.c_str());
- if(MYDEBUG)
- MESSAGE("LoadCellsOnEntity - theMeshOnEntity.myEntity = "<<theMeshOnEntity.myEntity<<
- "; iGeomElemEnd = "<<iGeomElemEnd<<"; theFamilyName = '"<<theFamilyName<<"'");
- VISU::TMesh &aMesh = myMeshMap[theMeshOnEntity.myMeshName];
- int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- int medId = getIdMedType(aGeomElemVector[iGeomElem]);
- int nbMedNodes = med2vtk[medId].medNbNodes;
- int nbVtkNodes = med2vtk[medId].vtkNbNodes;
- int aVtkType = med2vtk[medId].vtkType;
- med_geometrie_element aMedType = med2vtk[medId].medType;
- med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_CONN,aMedEntity,aMedType,MED_NOD);
- if (iNumElemEnd > 0) {
- med_booleen iname_elem, inum_elem;
- valarray<med_int> num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd);
- valarray<char> name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1);
- med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim);
- if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<<med2vtk[medId].medName<<
- "; iNumElemEnd = "<<iNumElemEnd<<"; aNbConnForElem = "<<aNbConnForElem);
- valarray<med_int> conn(aNbConnForElem*iNumElemEnd);
- ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE,
- &name_elem[0],&iname_elem,&num_elem[0],&inum_elem,
- &num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD);
- if (ret < 0) throw std::runtime_error("LoadCellsOnEntity >> MEDelementsLire(...)");
- if(!isCellsLoaded){
- VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType];
- aConnForCellType.resize(iNumElemEnd);
- valarray<med_int> aConnect(nbMedNodes);
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
- VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem];
- anArray.resize(nbVtkNodes);
- for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) {
- aConnect[k] = conn[kj+k] - 1;
- }
- switch(aMedType){
- case MED_TETRA4 :
- case MED_TETRA10 :
- anArray[0] = aConnect[0];
- anArray[1] = aConnect[1];
- anArray[2] = aConnect[3];
- anArray[3] = aConnect[2];
- break;
- case MED_PYRA5 :
- case MED_PYRA13 :
- anArray[0] = aConnect[0];
- anArray[1] = aConnect[3];
- anArray[2] = aConnect[2];
- anArray[3] = aConnect[1];
- anArray[4] = aConnect[4];
- break;
- default:
- for (int k = 0; k < nbVtkNodes; k++)
- anArray[k] = aConnect[k];
- }
- for (int k = 0; k < nbVtkNodes; k++)
- if(anArray[k] < 0 || aNbPoints <= anArray[k]){
- static QString aString;
- aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d](%d) < 0",aNbPoints,iNumElem,k,anArray[k]);
- throw std::runtime_error(aString.latin1());
- }
- }
- }
- //Filling aFamily SubMesh
- if(isFamilyPresent){
- VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType];
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
- if(num_fam_elem[iNumElem] == aFamily.myId)
- aSubMeshOnCellType.insert(iNumElem);
- }
- }
- }
- return 1;
- }catch(std::runtime_error& exc){
- theMeshOnEntity.myCellsConn.clear();
- throw std::runtime_error(exc.what());
- }catch(...){
- theMeshOnEntity.myCellsConn.clear();
- throw std::runtime_error("Unknown exception !!!");
- }
- return 0;
-}
-
-int VISU_MedConvertor::LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity,
- const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&)
-{
- //Check on loading already done
- if(!theValForTime.myValForCells.empty()) return 0;
- //Main part of code
- med_int ncomp = MEDnChamp(fid,theField.myId);
- if(ncomp < 0) throw std::runtime_error("LoadField >> MEDnChamp(fid,i)");
- valarray<char> comp('\0',ncomp*MED_TAILLE_PNOM + 1);
- valarray<char> unit('\0',ncomp*MED_TAILLE_PNOM + 1);
- char aFieldName[MED_TAILLE_NOM + 1] = "";
- med_type_champ type_field;
- if(MEDchampInfo(fid,theField.myId,aFieldName,&type_field,&comp[0],&unit[0],ncomp) < 0)
- throw std::runtime_error(string("LoadField >> MEDchampInfo(...)"));
- int iGeomElemEnd;
- med_geometrie_element* aGeomElemVector;
- const VISU::TEntity& anEntity = theField.myEntity;
- GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
- med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- if(MYDEBUG) {
- MESSAGE("LoadField - aFieldName = '"<<aFieldName<<"'; anEntity = "<<anEntity<<"; iGeomElemEnd = "<<iGeomElemEnd);
- MESSAGE("LoadField - ncomp = "<<ncomp<<"; type_field = "<<type_field<<"; myId = "<<theValForTime.myId);
- }
- for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
- med_int iTimeStampEnd = MEDnPasdetemps(fid,aFieldName,aMedEntity,aGeom);
- if(iTimeStampEnd > 0) {
- char aMeshName[MED_TAILLE_NOM+1] = "";
- med_int ngauss = 0, numdt = 0, numo = 0;
- char dt_unit[MED_TAILLE_PNOM+1] = "";
- med_float dt = 0;
- ret = MEDpasdetempsInfo(fid,aFieldName,aMedEntity,aGeom,theValForTime.myId,
- aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo);
- if(ret < 0) throw std::runtime_error("LoadField >> MEDpasdetempsInfo(...)");
- med_int nval = MEDnVal(fid,aFieldName,aMedEntity,aGeom,numdt,numo);
- if (nval <= 0) throw std::runtime_error("LoadField >> MEDnVal(...) - nval <= 0");
- else{
- //Checking for accordance between the mesh and the field on number of geomterical elements
- int aVtkType = med2vtkCellType(aGeom);
- const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
- VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
- if(aCellsConnIter == aCellsConn.end()) throw std::runtime_error("LoadField - There is no the geom. elem. on the mesh !!!");
- const VISU::TMeshOnEntity::TConnForCellType aConnForCellType = aCellsConnIter->second;
- if(aConnForCellType.size() != nval) throw std::runtime_error("LoadField - Size of values and size of mesh not equal !!!");
- if(MYDEBUG) MESSAGE("LoadField - aGeom = "<<aGeom<<"; nval = "<<nval<<"; iTimeStampEnd = "<<iTimeStampEnd);
- VISU::TField::TValForCellsWithType &anArray = theValForTime.myValForCells[aVtkType];
- int jEnd = theField.myNbComp*nval;
- anArray.resize(jEnd);
- char pflname[MED_TAILLE_NOM + 1] = "";
- switch(type_field){
- case MED_REEL64 : {
- valarray<med_float> valr(jEnd);
- ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL,
- pflname,aMedEntity,aGeom,numdt,numo);
- for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j];
- break;
- }
- //case MED_INT64 : //valarray<long long> valr(jEnd);
- case MED_INT32 : //valarray<long int> valr(jEnd);
- case MED_INT : {
- valarray<med_int> valr(jEnd);
- ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL,
- pflname,aMedEntity,aGeom,numdt,numo);
- for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j];
- break;
- }
- default :
- throw std::runtime_error("LoadField >> Value of med_type_champ for the field is wrong !!!");
- }
- if(ret < 0) throw std::runtime_error("ChampLire >> MEDchampLire(...)");
- }
- }
- }
- return 1;
-}
+++ /dev/null
-// Copyright (C) 2003 CEA/DEN, EDF R&D
-//
-//
-//
-// File : VISU_MedConvertor.hxx
-// Author : Alexey PETROV
-// Module : VISU
-
-#ifndef VISU_MedConvertor_HeaderFile
-#define VISU_MedConvertor_HeaderFile
-
-#include "VISU_Convertor_impl.hxx"
-
-extern "C"{
-#include <med.h>
-}
-
-class VISU_MedConvertor: public VISU_Convertor_impl{
- VISU_MedConvertor();
- VISU_MedConvertor(const VISU_MedConvertor&);
-public:
- VISU_MedConvertor(const string& theFileName) throw (std::runtime_error&);
- virtual VISU_Convertor* Build() throw (std::runtime_error&);
-protected:
- QFileInfo myFileInfo;
-
- virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName = "")
- throw (std::runtime_error&);
- virtual int LoadMeshOnGroup(VISU::TMesh& theMesh,
- const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
- throw (std::runtime_error&);
- virtual int LoadFieldOnMesh(VISU::TMesh& theMesh,
- VISU::TMeshOnEntity& theMeshOnEntity,
- VISU::TField& theField,
- VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&);
-
- int LoadPoints(const med_idt& fid, VISU::TMesh& theMesh,
- const string& theFamilyName = "")
- throw (std::runtime_error&);
- int LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName = "")
- throw (std::runtime_error&);
- int LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity,
- const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
- throw (std::runtime_error&);
-};
-
-#endif