For another project, please consult its home page to locate the current issue tracker.
| View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||
| 0007474 | VTK | (No Category) | public | 2008-08-08 14:52 | 2013-04-05 20:17 | ||||
| Reporter | Gerrick Bivins | ||||||||
| Assigned To | David Cole | ||||||||
| Priority | normal | Severity | block | Reproducibility | always | ||||
| Status | closed | Resolution | fixed | ||||||
| Platform | OS | OS Version | |||||||
| Product Version | |||||||||
| Target Version | Fixed in Version | ||||||||
| Summary | 0007474: VRML Exporter doesn't work | ||||||||
| Description | http://www.vtk.org/pipermail/vtk-developers/2008-August/005436.html [^] No one seems to respond to my emails on the list for some reason. | ||||||||
| Additional Information | I have the patch created for this | ||||||||
| Tags | No tags attached. | ||||||||
| Project | |||||||||
| Type | |||||||||
| Attached Files | Index: vtkVRMLExporter.h
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.h,v
retrieving revision 1.36
diff -u -8 -p -r1.36 vtkVRMLExporter.h
--- vtkVRMLExporter.h 24 Dec 2003 16:40:51 -0000 1.36
+++ vtkVRMLExporter.h 7 Aug 2008 21:44:09 -0000
@@ -27,16 +27,18 @@
#include "vtkExporter.h"
class vtkLight;
class vtkActor;
class vtkPoints;
class vtkDataArray;
class vtkUnsignedCharArray;
+class vtkPolyData;
+class vtkPointData;
class VTK_RENDERING_EXPORT vtkVRMLExporter : public vtkExporter
{
public:
static vtkVRMLExporter *New();
vtkTypeRevisionMacro(vtkVRMLExporter,vtkExporter);
void PrintSelf(ostream& os, vtkIndent indent);
@@ -60,16 +62,20 @@ protected:
~vtkVRMLExporter();
void WriteData();
void WriteALight(vtkLight *aLight, FILE *fp);
void WriteAnActor(vtkActor *anActor, FILE *fp);
void WritePointData(vtkPoints *points, vtkDataArray *normals,
vtkDataArray *tcoords, vtkUnsignedCharArray *colors,
FILE *fp);
+ void WriteShapeBegin(vtkActor* actor, FILE *fileP,
+ vtkPolyData *polyData,vtkPointData *pntData,
+ vtkUnsignedCharArray *color);
+ void WriteShapeEnd( FILE *fileP );
char *FileName;
FILE *FilePointer;
double Speed;
private:
vtkVRMLExporter(const vtkVRMLExporter&); // Not implemented.
void operator=(const vtkVRMLExporter&); // Not implemented.
};
Index: vtkVRMLExporter.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.cxx,v
retrieving revision 1.82
diff -u -8 -p -r1.82 vtkVRMLExporter.cxx
--- vtkVRMLExporter.cxx 23 Feb 2008 17:18:46 -0000 1.82
+++ vtkVRMLExporter.cxx 7 Aug 2008 21:44:20 -0000
@@ -135,26 +135,29 @@ void vtkVRMLExporter::WriteData()
fprintf(fp," position %f %f %f\n",cam->GetPosition()[0],
cam->GetPosition()[1], cam->GetPosition()[2]);
fprintf(fp," description \"Default View\"\n");
tempd = cam->GetOrientationWXYZ();
fprintf(fp," orientation %g %g %g %g\n }\n", tempd[1], tempd[2],
tempd[3], tempd[0]*3.1415926/180.0);
// do the lights first the ambient then the others
- fprintf(fp," NavigationInfo {\n type [\"EXAMINE\",\"FLY\"]\n speed %f\n", this->Speed);
+ fprintf(fp,
+ " NavigationInfo {\n type [\"EXAMINE\",\"FLY\"]\n speed %f\n",
+ this->Speed);
if (ren->GetLights()->GetNumberOfItems() == 0)
{
fprintf(fp," headlight TRUE}\n\n");
}
else
{
fprintf(fp," headlight FALSE}\n\n");
}
- fprintf(fp," DirectionalLight { ambientIntensity 1 intensity 0 # ambient light\n");
+ fprintf(fp,
+ " DirectionalLight { ambientIntensity 1 intensity 0 # ambient light\n");
fprintf(fp," color %f %f %f }\n\n", ren->GetAmbient()[0],
ren->GetAmbient()[1], ren->GetAmbient()[2]);
// make sure we have a default light
// if we dont then use a headlight
lc = ren->GetLights();
vtkCollectionSimpleIterator lsit;
for (lc->InitTraversal(lsit); (aLight = lc->GetNextLight(lsit)); )
@@ -169,17 +172,16 @@ void vtkVRMLExporter::WriteData()
for (ac->InitTraversal(ait); (anActor = ac->GetNextActor(ait)); )
{
for (anActor->InitPathTraversal(); (apath=anActor->GetNextPath()); )
{
aPart=static_cast<vtkActor *>(apath->GetLastNode()->GetViewProp());
this->WriteAnActor(aPart, fp);
}
}
-
if (!this->FilePointer)
{
fclose(fp);
}
}
void vtkVRMLExporter::WriteALight(vtkLight *aLight, FILE *fp)
{
@@ -249,23 +251,27 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
double tempf2;
int pointDataWritten = 0;
vtkPolyDataMapper *pm;
vtkUnsignedCharArray *colors;
double *p;
unsigned char *c;
vtkTransform *trans;
int totalValues;
-
+ anActor->Print(std::cout);
+
// see if the actor has a mapper. it could be an assembly
if (anActor->GetMapper() == NULL)
{
return;
}
-
+ if (anActor->GetVisibility() == 0)
+ {
+ return;
+ }
// first stuff out the transform
trans = vtkTransform::New();
trans->SetMatrix(anActor->vtkProp3D::GetMatrix());
fprintf(fp," Transform {\n");
tempd = trans->GetPosition();
fprintf(fp," translation %g %g %g\n", tempd[0], tempd[1], tempd[2]);
tempd = trans->GetOrientationWXYZ();
@@ -315,152 +321,20 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
}
points = pd->GetPoints();
pntData = pd->GetPointData();
normals = pntData->GetNormals();
tcoords = pntData->GetTCoords();
colors = pm->MapScalars(1.0);
- fprintf(fp," Shape {\n");
-
- // write out the material properties to the mat file
- fprintf(fp," appearance Appearance {\n");
- fprintf(fp," material Material {\n");
- prop = anActor->GetProperty();
- fprintf(fp," ambientIntensity %g\n", prop->GetAmbient());
- // if we don't have colors and we have only lines & points
- // use emissive to color them
- if (!(normals || colors || pd->GetNumberOfPolys() ||
- pd->GetNumberOfStrips()))
- {
- tempf2 = prop->GetAmbient();
- tempd = prop->GetAmbientColor();
- fprintf(fp," emissiveColor %g %g %g\n",
- tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
- }
- tempf2 = prop->GetDiffuse();
- tempd = prop->GetDiffuseColor();
- fprintf(fp," diffuseColor %g %g %g\n",
- tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
- tempf2 = prop->GetSpecular();
- tempd = prop->GetSpecularColor();
- fprintf(fp," specularColor %g %g %g\n",
- tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
- fprintf(fp," shininess %g\n",prop->GetSpecularPower()/128.0);
- fprintf(fp," transparency %g\n",1.0 - prop->GetOpacity());
- fprintf(fp," }\n"); // close matrial
-
- // is there a texture map
- if (anActor->GetTexture())
- {
- vtkTexture *aTexture = anActor->GetTexture();
- int *size, xsize, ysize, bpp;
- vtkDataArray *scalars;
- vtkDataArray *mappedScalars;
- unsigned char *txtrData;
-
- // make sure it is updated and then get some info
- if (aTexture->GetInput() == NULL)
- {
- vtkErrorMacro(<< "texture has no input!\n");
- return;
- }
- aTexture->GetInput()->Update();
- size = aTexture->GetInput()->GetDimensions();
- scalars = aTexture->GetInput()->GetPointData()->GetScalars();
-
- // make sure scalars are non null
- if (!scalars)
- {
- vtkErrorMacro(<< "No scalar values found for texture input!\n");
- return;
- }
-
- // make sure using unsigned char data of color scalars type
- if (aTexture->GetMapColorScalarsThroughLookupTable () ||
- (scalars->GetDataType() != VTK_UNSIGNED_CHAR) )
- {
- mappedScalars = aTexture->GetMappedScalars ();
- }
- else
- {
- mappedScalars = scalars;
- }
-
- // we only support 2d texture maps right now
- // so one of the three sizes must be 1, but it
- // could be any of them, so lets find it
- if (size[0] == 1)
- {
- xsize = size[1]; ysize = size[2];
- }
- else
- {
- xsize = size[0];
- if (size[1] == 1)
- {
- ysize = size[2];
- }
- else
- {
- ysize = size[1];
- if (size[2] != 1)
- {
- vtkErrorMacro(<< "3D texture maps currently are not supported!\n");
- return;
- }
- }
- }
-
- fprintf(fp," texture PixelTexture {\n");
- bpp = mappedScalars->GetNumberOfComponents();
- fprintf(fp," image %i %i %i\n", xsize, ysize, bpp);
- txtrData = static_cast<vtkUnsignedCharArray*>(mappedScalars)->GetPointer(0);
- totalValues = xsize*ysize;
- for (i = 0; i < totalValues; i++)
- {
- fprintf(fp,"0x%.2x",*txtrData);
- txtrData++;
- if (bpp > 1)
- {
- fprintf(fp,"%.2x",*txtrData);
- txtrData++;
- }
- if (bpp > 2)
- {
- fprintf(fp,"%.2x",*txtrData);
- txtrData++;
- }
- if (bpp > 3)
- {
- fprintf(fp,"%.2x",*txtrData);
- txtrData++;
- }
- if (i%8 == 0)
- {
- fprintf(fp,"\n");
- }
- else
- {
- fprintf(fp," ");
- }
- }
- if (!(aTexture->GetRepeat()))
- {
- fprintf(fp," repeatS FALSE\n");
- fprintf(fp," repeatT FALSE\n");
- }
- fprintf(fp," }\n"); // close texture
- }
- fprintf(fp," }\n"); // close appearance
-
// write out polys if any
if (pd->GetNumberOfPolys() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry IndexedFaceSet {\n");
// two sided lighting ? for now assume it is on
fprintf(fp," solid FALSE\n");
if (!pointDataWritten)
{
this->WritePointData(points, normals, tcoords, colors, fp);
pointDataWritten = 1;
}
@@ -491,21 +365,23 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
{
// treating vtkIdType as int
fprintf(fp,"%i, ", static_cast<int>(indx[i]));
}
fprintf(fp,"-1,\n");
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
// write out tstrips if any
if (pd->GetNumberOfStrips() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry IndexedFaceSet {\n");
if (!pointDataWritten)
{
this->WritePointData(points, normals, tcoords, colors, fp);
pointDataWritten = 1;
}
else
{
@@ -542,21 +418,23 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
// treating vtkIdType as int
fprintf(fp," %i, %i, %i, -1,\n",
static_cast<int>(indx[i1]),
static_cast<int>(indx[i2]),static_cast<int>(indx[i]));
}
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
// write out lines if any
if (pd->GetNumberOfLines() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry IndexedLineSet {\n");
if (!pointDataWritten)
{
this->WritePointData(points, NULL, NULL, colors, fp);
pointDataWritten = 1;
}
else
{
@@ -577,72 +455,219 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
{
// treating vtkIdType as int
fprintf(fp,"%i, ", static_cast<int>(indx[i]));
}
fprintf(fp,"-1,\n");
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
// write out verts if any
if (pd->GetNumberOfVerts() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry PointSet {\n");
cells = pd->GetVerts();
fprintf(fp," coord Coordinate {");
fprintf(fp," point [");
for (cells->InitTraversal(); cells->GetNextCell(npts,indx); )
{
fprintf(fp," ");
for (i = 0; i < npts; i++)
{
p = points->GetPoint(indx[i]);
fprintf (fp," %g %g %g,\n", p[0], p[1], p[2]);
}
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
if (colors)
+ {
+ fprintf(fp," color Color {");
+ fprintf(fp," color [");
+ for (cells->InitTraversal(); cells->GetNextCell(npts,indx); )
{
- fprintf(fp," color Color {");
- fprintf(fp," color [");
- for (cells->InitTraversal(); cells->GetNextCell(npts,indx); )
+ fprintf(fp," ");
+ for (i = 0; i < npts; i++)
{
- fprintf(fp," ");
- for (i = 0; i < npts; i++)
- {
- c = colors->GetPointer(4*indx[i]);
- fprintf (fp," %g %g %g,\n", c[0]/255.0, c[1]/255.0,
+ c = colors->GetPointer(4*indx[i]);
+ fprintf (fp," %g %g %g,\n", c[0]/255.0, c[1]/255.0,
c[2]/255.0);
- }
}
- fprintf(fp," ]\n");
- fprintf(fp," }\n");
}
-
+ fprintf(fp," ]\n");
+ fprintf(fp," }\n");
+ }
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
- fprintf(fp," }\n"); // close the Shape
fprintf(fp," ]\n"); // close the original transforms children
fprintf(fp," }\n"); // close the original transform
if (gf)
{
gf->Delete();
}
pm->Delete();
}
-
+void vtkVRMLExporter::WriteShapeBegin( vtkActor* actor, FILE *fileP,
+ vtkPolyData* polyData,
+ vtkPointData* pntData,
+ vtkUnsignedCharArray* color)
+{
+ double *tempd;
+ double tempf2;
+
+ fprintf(fileP," Shape {\n");
+ vtkProperty* props = 0;
+ // write out the material properties to the mat file
+ fprintf(fileP," appearance Appearance {\n");
+ fprintf(fileP," material Material {\n");
+ props = actor->GetProperty();
+ fprintf(fileP," ambientIntensity %g\n", props->GetAmbient());
+ // if we don't have colors and we have only lines & points
+ // use emissive to color them
+ if (!(pntData->GetNormals() || color || polyData->GetNumberOfPolys() ||
+ polyData->GetNumberOfStrips()))
+ {
+ tempf2 = props->GetAmbient();
+ tempd = props->GetAmbientColor();
+ fprintf(fileP," emissiveColor %g %g %g\n",
+ tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
+ }
+ tempf2 = props->GetDiffuse();
+ tempd = props->GetDiffuseColor();
+ fprintf(fileP," diffuseColor %g %g %g\n",
+ tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
+ tempf2 = props->GetSpecular();
+ tempd = props->GetSpecularColor();
+ fprintf(fileP," specularColor %g %g %g\n",
+ tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
+ fprintf(fileP," shininess %g\n",props->GetSpecularPower()/128.0);
+ fprintf(fileP," transparency %g\n",1.0-props->GetOpacity());
+ fprintf(fileP," }\n"); // close matrial
+
+ // is there a texture map
+ if (actor->GetTexture())
+ {
+ vtkTexture *aTexture = actor->GetTexture();
+ int *size, xsize, ysize, bpp;
+ vtkDataArray *scalars;
+ vtkDataArray *mappedScalars;
+ unsigned char *txtrData;
+
+ // make sure it is updated and then get some info
+ if (aTexture->GetInput() == NULL)
+ {
+ vtkErrorMacro(<< "texture has no input!\n");
+ return;
+ }
+ aTexture->GetInput()->Update();
+ size = aTexture->GetInput()->GetDimensions();
+ scalars = aTexture->GetInput()->GetPointData()->GetScalars();
+
+ // make sure scalars are non null
+ if (!scalars)
+ {
+ vtkErrorMacro(<< "No scalar values found for texture input!\n");
+ return;
+ }
+
+ // make sure using unsigned char data of color scalars type
+ if (aTexture->GetMapColorScalarsThroughLookupTable () ||
+ (scalars->GetDataType() != VTK_UNSIGNED_CHAR) )
+ {
+ mappedScalars = aTexture->GetMappedScalars ();
+ }
+ else
+ {
+ mappedScalars = scalars;
+ }
+
+ // we only support 2d texture maps right now
+ // so one of the three sizes must be 1, but it
+ // could be any of them, so lets find it
+ if (size[0] == 1)
+ {
+ xsize = size[1]; ysize = size[2];
+ }
+ else
+ {
+ xsize = size[0];
+ if (size[1] == 1)
+ {
+ ysize = size[2];
+ }
+ else
+ {
+ ysize = size[1];
+ if (size[2] != 1)
+ {
+ vtkErrorMacro(<< "3D texture maps currently are not supported!\n");
+ return;
+ }
+ }
+ }
+
+ fprintf(fileP," texture PixelTexture {\n");
+ bpp = mappedScalars->GetNumberOfComponents();
+ fprintf(fileP," image %i %i %i\n", xsize, ysize, bpp);
+ txtrData =
+ static_cast<vtkUnsignedCharArray*>(mappedScalars)->GetPointer(0);
+ int totalValues = xsize*ysize;
+ for (int i = 0; i < totalValues; i++)
+ {
+ fprintf(fileP,"0x%.2x",*txtrData);
+ txtrData++;
+ if (bpp > 1)
+ {
+ fprintf(fileP,"%.2x",*txtrData);
+ txtrData++;
+ }
+ if (bpp > 2)
+ {
+ fprintf(fileP,"%.2x",*txtrData);
+ txtrData++;
+ }
+ if (bpp > 3)
+ {
+ fprintf(fileP,"%.2x",*txtrData);
+ txtrData++;
+ }
+ if (i%8 == 0)
+ {
+ fprintf(fileP,"\n");
+ }
+ else
+ {
+ fprintf(fileP," ");
+ }
+ }
+ if (!(aTexture->GetRepeat()))
+ {
+ fprintf(fileP," repeatS FALSE\n");
+ fprintf(fileP," repeatT FALSE\n");
+ }
+ fprintf(fileP," }\n"); // close texture
+ }
+ fprintf(fileP," }\n"); // close appearance
+}
+void vtkVRMLExporter::WriteShapeEnd( FILE *fileP )
+{
+ fprintf(fileP," }\n"); // close the Shape
+}
void vtkVRMLExporter::WritePointData(vtkPoints *points, vtkDataArray *normals,
vtkDataArray *tcoords,
vtkUnsignedCharArray *colors, FILE *fp)
{
+
double *p;
int i;
unsigned char *c;
// write out the points
fprintf(fp," coord DEF VTKcoordinates Coordinate {\n");
fprintf(fp," point [\n");
for (i = 0; i < points->GetNumberOfPoints(); i++)
Index: vtkVRMLExporter.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.cxx,v
retrieving revision 1.82
diff -u -8 -p -r1.82 vtkVRMLExporter.cxx
--- vtkVRMLExporter.cxx 23 Feb 2008 17:18:46 -0000 1.82
+++ vtkVRMLExporter.cxx 11 Aug 2008 15:42:44 -0000
@@ -135,26 +135,29 @@ void vtkVRMLExporter::WriteData()
fprintf(fp," position %f %f %f\n",cam->GetPosition()[0],
cam->GetPosition()[1], cam->GetPosition()[2]);
fprintf(fp," description \"Default View\"\n");
tempd = cam->GetOrientationWXYZ();
fprintf(fp," orientation %g %g %g %g\n }\n", tempd[1], tempd[2],
tempd[3], tempd[0]*3.1415926/180.0);
// do the lights first the ambient then the others
- fprintf(fp," NavigationInfo {\n type [\"EXAMINE\",\"FLY\"]\n speed %f\n", this->Speed);
+ fprintf(fp,
+ " NavigationInfo {\n type [\"EXAMINE\",\"FLY\"]\n speed %f\n",
+ this->Speed);
if (ren->GetLights()->GetNumberOfItems() == 0)
{
fprintf(fp," headlight TRUE}\n\n");
}
else
{
fprintf(fp," headlight FALSE}\n\n");
}
- fprintf(fp," DirectionalLight { ambientIntensity 1 intensity 0 # ambient light\n");
+ fprintf(fp,
+ " DirectionalLight { ambientIntensity 1 intensity 0 # ambient light\n");
fprintf(fp," color %f %f %f }\n\n", ren->GetAmbient()[0],
ren->GetAmbient()[1], ren->GetAmbient()[2]);
// make sure we have a default light
// if we dont then use a headlight
lc = ren->GetLights();
vtkCollectionSimpleIterator lsit;
for (lc->InitTraversal(lsit); (aLight = lc->GetNextLight(lsit)); )
@@ -169,17 +172,16 @@ void vtkVRMLExporter::WriteData()
for (ac->InitTraversal(ait); (anActor = ac->GetNextActor(ait)); )
{
for (anActor->InitPathTraversal(); (apath=anActor->GetNextPath()); )
{
aPart=static_cast<vtkActor *>(apath->GetLastNode()->GetViewProp());
this->WriteAnActor(aPart, fp);
}
}
-
if (!this->FilePointer)
{
fclose(fp);
}
}
void vtkVRMLExporter::WriteALight(vtkLight *aLight, FILE *fp)
{
@@ -249,23 +251,26 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
double tempf2;
int pointDataWritten = 0;
vtkPolyDataMapper *pm;
vtkUnsignedCharArray *colors;
double *p;
unsigned char *c;
vtkTransform *trans;
int totalValues;
-
+
// see if the actor has a mapper. it could be an assembly
if (anActor->GetMapper() == NULL)
{
return;
}
-
+ if (anActor->GetVisibility() == 0)
+ {
+ return;
+ }
// first stuff out the transform
trans = vtkTransform::New();
trans->SetMatrix(anActor->vtkProp3D::GetMatrix());
fprintf(fp," Transform {\n");
tempd = trans->GetPosition();
fprintf(fp," translation %g %g %g\n", tempd[0], tempd[1], tempd[2]);
tempd = trans->GetOrientationWXYZ();
@@ -315,152 +320,20 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
}
points = pd->GetPoints();
pntData = pd->GetPointData();
normals = pntData->GetNormals();
tcoords = pntData->GetTCoords();
colors = pm->MapScalars(1.0);
- fprintf(fp," Shape {\n");
-
- // write out the material properties to the mat file
- fprintf(fp," appearance Appearance {\n");
- fprintf(fp," material Material {\n");
- prop = anActor->GetProperty();
- fprintf(fp," ambientIntensity %g\n", prop->GetAmbient());
- // if we don't have colors and we have only lines & points
- // use emissive to color them
- if (!(normals || colors || pd->GetNumberOfPolys() ||
- pd->GetNumberOfStrips()))
- {
- tempf2 = prop->GetAmbient();
- tempd = prop->GetAmbientColor();
- fprintf(fp," emissiveColor %g %g %g\n",
- tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
- }
- tempf2 = prop->GetDiffuse();
- tempd = prop->GetDiffuseColor();
- fprintf(fp," diffuseColor %g %g %g\n",
- tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
- tempf2 = prop->GetSpecular();
- tempd = prop->GetSpecularColor();
- fprintf(fp," specularColor %g %g %g\n",
- tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
- fprintf(fp," shininess %g\n",prop->GetSpecularPower()/128.0);
- fprintf(fp," transparency %g\n",1.0 - prop->GetOpacity());
- fprintf(fp," }\n"); // close matrial
-
- // is there a texture map
- if (anActor->GetTexture())
- {
- vtkTexture *aTexture = anActor->GetTexture();
- int *size, xsize, ysize, bpp;
- vtkDataArray *scalars;
- vtkDataArray *mappedScalars;
- unsigned char *txtrData;
-
- // make sure it is updated and then get some info
- if (aTexture->GetInput() == NULL)
- {
- vtkErrorMacro(<< "texture has no input!\n");
- return;
- }
- aTexture->GetInput()->Update();
- size = aTexture->GetInput()->GetDimensions();
- scalars = aTexture->GetInput()->GetPointData()->GetScalars();
-
- // make sure scalars are non null
- if (!scalars)
- {
- vtkErrorMacro(<< "No scalar values found for texture input!\n");
- return;
- }
-
- // make sure using unsigned char data of color scalars type
- if (aTexture->GetMapColorScalarsThroughLookupTable () ||
- (scalars->GetDataType() != VTK_UNSIGNED_CHAR) )
- {
- mappedScalars = aTexture->GetMappedScalars ();
- }
- else
- {
- mappedScalars = scalars;
- }
-
- // we only support 2d texture maps right now
- // so one of the three sizes must be 1, but it
- // could be any of them, so lets find it
- if (size[0] == 1)
- {
- xsize = size[1]; ysize = size[2];
- }
- else
- {
- xsize = size[0];
- if (size[1] == 1)
- {
- ysize = size[2];
- }
- else
- {
- ysize = size[1];
- if (size[2] != 1)
- {
- vtkErrorMacro(<< "3D texture maps currently are not supported!\n");
- return;
- }
- }
- }
-
- fprintf(fp," texture PixelTexture {\n");
- bpp = mappedScalars->GetNumberOfComponents();
- fprintf(fp," image %i %i %i\n", xsize, ysize, bpp);
- txtrData = static_cast<vtkUnsignedCharArray*>(mappedScalars)->GetPointer(0);
- totalValues = xsize*ysize;
- for (i = 0; i < totalValues; i++)
- {
- fprintf(fp,"0x%.2x",*txtrData);
- txtrData++;
- if (bpp > 1)
- {
- fprintf(fp,"%.2x",*txtrData);
- txtrData++;
- }
- if (bpp > 2)
- {
- fprintf(fp,"%.2x",*txtrData);
- txtrData++;
- }
- if (bpp > 3)
- {
- fprintf(fp,"%.2x",*txtrData);
- txtrData++;
- }
- if (i%8 == 0)
- {
- fprintf(fp,"\n");
- }
- else
- {
- fprintf(fp," ");
- }
- }
- if (!(aTexture->GetRepeat()))
- {
- fprintf(fp," repeatS FALSE\n");
- fprintf(fp," repeatT FALSE\n");
- }
- fprintf(fp," }\n"); // close texture
- }
- fprintf(fp," }\n"); // close appearance
-
// write out polys if any
if (pd->GetNumberOfPolys() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry IndexedFaceSet {\n");
// two sided lighting ? for now assume it is on
fprintf(fp," solid FALSE\n");
if (!pointDataWritten)
{
this->WritePointData(points, normals, tcoords, colors, fp);
pointDataWritten = 1;
}
@@ -491,21 +364,23 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
{
// treating vtkIdType as int
fprintf(fp,"%i, ", static_cast<int>(indx[i]));
}
fprintf(fp,"-1,\n");
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
// write out tstrips if any
if (pd->GetNumberOfStrips() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry IndexedFaceSet {\n");
if (!pointDataWritten)
{
this->WritePointData(points, normals, tcoords, colors, fp);
pointDataWritten = 1;
}
else
{
@@ -542,21 +417,23 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
// treating vtkIdType as int
fprintf(fp," %i, %i, %i, -1,\n",
static_cast<int>(indx[i1]),
static_cast<int>(indx[i2]),static_cast<int>(indx[i]));
}
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
// write out lines if any
if (pd->GetNumberOfLines() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry IndexedLineSet {\n");
if (!pointDataWritten)
{
this->WritePointData(points, NULL, NULL, colors, fp);
pointDataWritten = 1;
}
else
{
@@ -577,72 +454,219 @@ void vtkVRMLExporter::WriteAnActor(vtkAc
{
// treating vtkIdType as int
fprintf(fp,"%i, ", static_cast<int>(indx[i]));
}
fprintf(fp,"-1,\n");
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
// write out verts if any
if (pd->GetNumberOfVerts() > 0)
{
+ WriteShapeBegin(anActor,fp, pd, pntData, colors);
fprintf(fp," geometry PointSet {\n");
cells = pd->GetVerts();
fprintf(fp," coord Coordinate {");
fprintf(fp," point [");
for (cells->InitTraversal(); cells->GetNextCell(npts,indx); )
{
fprintf(fp," ");
for (i = 0; i < npts; i++)
{
p = points->GetPoint(indx[i]);
fprintf (fp," %g %g %g,\n", p[0], p[1], p[2]);
}
}
fprintf(fp," ]\n");
fprintf(fp," }\n");
if (colors)
+ {
+ fprintf(fp," color Color {");
+ fprintf(fp," color [");
+ for (cells->InitTraversal(); cells->GetNextCell(npts,indx); )
{
- fprintf(fp," color Color {");
- fprintf(fp," color [");
- for (cells->InitTraversal(); cells->GetNextCell(npts,indx); )
+ fprintf(fp," ");
+ for (i = 0; i < npts; i++)
{
- fprintf(fp," ");
- for (i = 0; i < npts; i++)
- {
- c = colors->GetPointer(4*indx[i]);
- fprintf (fp," %g %g %g,\n", c[0]/255.0, c[1]/255.0,
+ c = colors->GetPointer(4*indx[i]);
+ fprintf (fp," %g %g %g,\n", c[0]/255.0, c[1]/255.0,
c[2]/255.0);
- }
}
- fprintf(fp," ]\n");
- fprintf(fp," }\n");
}
-
+ fprintf(fp," ]\n");
+ fprintf(fp," }\n");
+ }
fprintf(fp," }\n");
+ WriteShapeEnd(fp);
}
- fprintf(fp," }\n"); // close the Shape
fprintf(fp," ]\n"); // close the original transforms children
fprintf(fp," }\n"); // close the original transform
if (gf)
{
gf->Delete();
}
pm->Delete();
}
-
+void vtkVRMLExporter::WriteShapeBegin( vtkActor* actor, FILE *fileP,
+ vtkPolyData* polyData,
+ vtkPointData* pntData,
+ vtkUnsignedCharArray* color)
+{
+ double *tempd;
+ double tempf2;
+
+ fprintf(fileP," Shape {\n");
+ vtkProperty* props = 0;
+ // write out the material properties to the mat file
+ fprintf(fileP," appearance Appearance {\n");
+ fprintf(fileP," material Material {\n");
+ props = actor->GetProperty();
+ fprintf(fileP," ambientIntensity %g\n", props->GetAmbient());
+ // if we don't have colors and we have only lines & points
+ // use emissive to color them
+ if (!(pntData->GetNormals() || color || polyData->GetNumberOfPolys() ||
+ polyData->GetNumberOfStrips()))
+ {
+ tempf2 = props->GetAmbient();
+ tempd = props->GetAmbientColor();
+ fprintf(fileP," emissiveColor %g %g %g\n",
+ tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
+ }
+ tempf2 = props->GetDiffuse();
+ tempd = props->GetDiffuseColor();
+ fprintf(fileP," diffuseColor %g %g %g\n",
+ tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
+ tempf2 = props->GetSpecular();
+ tempd = props->GetSpecularColor();
+ fprintf(fileP," specularColor %g %g %g\n",
+ tempd[0]*tempf2, tempd[1]*tempf2, tempd[2]*tempf2);
+ fprintf(fileP," shininess %g\n",props->GetSpecularPower()/128.0);
+ fprintf(fileP," transparency %g\n",1.0-props->GetOpacity());
+ fprintf(fileP," }\n"); // close matrial
+
+ // is there a texture map
+ if (actor->GetTexture())
+ {
+ vtkTexture *aTexture = actor->GetTexture();
+ int *size, xsize, ysize, bpp;
+ vtkDataArray *scalars;
+ vtkDataArray *mappedScalars;
+ unsigned char *txtrData;
+
+ // make sure it is updated and then get some info
+ if (aTexture->GetInput() == NULL)
+ {
+ vtkErrorMacro(<< "texture has no input!\n");
+ return;
+ }
+ aTexture->GetInput()->Update();
+ size = aTexture->GetInput()->GetDimensions();
+ scalars = aTexture->GetInput()->GetPointData()->GetScalars();
+
+ // make sure scalars are non null
+ if (!scalars)
+ {
+ vtkErrorMacro(<< "No scalar values found for texture input!\n");
+ return;
+ }
+
+ // make sure using unsigned char data of color scalars type
+ if (aTexture->GetMapColorScalarsThroughLookupTable () ||
+ (scalars->GetDataType() != VTK_UNSIGNED_CHAR) )
+ {
+ mappedScalars = aTexture->GetMappedScalars ();
+ }
+ else
+ {
+ mappedScalars = scalars;
+ }
+
+ // we only support 2d texture maps right now
+ // so one of the three sizes must be 1, but it
+ // could be any of them, so lets find it
+ if (size[0] == 1)
+ {
+ xsize = size[1]; ysize = size[2];
+ }
+ else
+ {
+ xsize = size[0];
+ if (size[1] == 1)
+ {
+ ysize = size[2];
+ }
+ else
+ {
+ ysize = size[1];
+ if (size[2] != 1)
+ {
+ vtkErrorMacro(<< "3D texture maps currently are not supported!\n");
+ return;
+ }
+ }
+ }
+
+ fprintf(fileP," texture PixelTexture {\n");
+ bpp = mappedScalars->GetNumberOfComponents();
+ fprintf(fileP," image %i %i %i\n", xsize, ysize, bpp);
+ txtrData =
+ static_cast<vtkUnsignedCharArray*>(mappedScalars)->GetPointer(0);
+ int totalValues = xsize*ysize;
+ for (int i = 0; i < totalValues; i++)
+ {
+ fprintf(fileP,"0x%.2x",*txtrData);
+ txtrData++;
+ if (bpp > 1)
+ {
+ fprintf(fileP,"%.2x",*txtrData);
+ txtrData++;
+ }
+ if (bpp > 2)
+ {
+ fprintf(fileP,"%.2x",*txtrData);
+ txtrData++;
+ }
+ if (bpp > 3)
+ {
+ fprintf(fileP,"%.2x",*txtrData);
+ txtrData++;
+ }
+ if (i%8 == 0)
+ {
+ fprintf(fileP,"\n");
+ }
+ else
+ {
+ fprintf(fileP," ");
+ }
+ }
+ if (!(aTexture->GetRepeat()))
+ {
+ fprintf(fileP," repeatS FALSE\n");
+ fprintf(fileP," repeatT FALSE\n");
+ }
+ fprintf(fileP," }\n"); // close texture
+ }
+ fprintf(fileP," }\n"); // close appearance
+}
+void vtkVRMLExporter::WriteShapeEnd( FILE *fileP )
+{
+ fprintf(fileP," }\n"); // close the Shape
+}
void vtkVRMLExporter::WritePointData(vtkPoints *points, vtkDataArray *normals,
vtkDataArray *tcoords,
vtkUnsignedCharArray *colors, FILE *fp)
{
+
double *p;
int i;
unsigned char *c;
// write out the points
fprintf(fp," coord DEF VTKcoordinates Coordinate {\n");
fprintf(fp," point [\n");
for (i = 0; i < points->GetNumberOfPoints(); i++)
| ||||||||
| Relationships | |
| Relationships |
| Notes | |
|
(0012981) Gerrick Bivins (reporter) 2008-08-11 11:46 |
I've updated the VRMLExporter fix |
|
(0012994) David Cole (developer) 2008-08-12 15:15 |
Fixed in CVS HEAD: /cvsroot/VTK/VTK/Rendering/vtkOBJExporter.cxx,v <-- Rendering/vtkOBJExporter.cxx new revision: 1.59; previous revision: 1.58 /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.cxx,v <-- Rendering/vtkVRMLExporter.cxx new revision: 1.83; previous revision: 1.82 /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.h,v <-- Rendering/vtkVRMLExporter.h new revision: 1.37; previous revision: 1.36 |
|
(0012995) David Cole (developer) 2008-08-12 16:03 |
And eliminate some warnings: /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.cxx,v <-- Rendering/vtkVRMLExporter.cxx new revision: 1.84; previous revision: 1.83 |
|
(0013028) David Cole (developer) 2008-08-14 17:09 |
Merged CVS HEAD fix to VTK-5-2 today: /cvsroot/VTK/VTK/Rendering/vtkOBJExporter.cxx,v <-- Rendering/vtkOBJExporter.cxx new revision: 1.58.2.1; previous revision: 1.58 /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.h,v <-- Rendering/vtkVRMLExporter.h new revision: 1.36.82.1; previous revision: 1.36 /cvsroot/VTK/VTK/Rendering/vtkVRMLExporter.cxx,v <-- Rendering/vtkVRMLExporter.cxx new revision: 1.82.2.1; previous revision: 1.82 |
| Notes |
| Issue History | |||
| Date Modified | Username | Field | Change |
| 2008-08-08 14:52 | Gerrick Bivins | New Issue | |
| 2008-08-08 14:52 | Gerrick Bivins | File Added: vtkVRMLExporter.h.patch | |
| 2008-08-08 14:52 | Gerrick Bivins | File Added: vtkVRMLExporter.cxx.patch | |
| 2008-08-11 11:45 | Gerrick Bivins | File Added: vtkVRMLExporter.cxx.08112008.patch | |
| 2008-08-11 11:46 | Gerrick Bivins | Note Added: 0012981 | |
| 2008-08-12 14:30 | David Cole | Status | backlog => tabled |
| 2008-08-12 14:30 | David Cole | Assigned To | => David Cole |
| 2008-08-12 15:15 | David Cole | Note Added: 0012994 | |
| 2008-08-12 16:03 | David Cole | Note Added: 0012995 | |
| 2008-08-14 17:09 | David Cole | Status | tabled => @80@ |
| 2008-08-14 17:09 | David Cole | Resolution | open => fixed |
| 2008-08-14 17:09 | David Cole | Note Added: 0013028 | |
| 2011-01-13 17:00 | Source_changeset_attached | => VTK master a2bd8391 | |
| 2011-01-13 17:00 | Source_changeset_attached | => VTK master 020ef709 | |
| 2011-06-16 13:11 | Zack Galbreath | Category | => (No Category) |
| 2013-04-05 20:17 | Berk Geveci | Status | customer review => closed |
| Issue History |
| Copyright © 2000 - 2018 MantisBT Team |