File: vtkXMLKWOpenFilePropertiesWriter.cxx

package info (click to toggle)
volview 3.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 25,204 kB
  • sloc: cpp: 132,585; ansic: 11,612; tcl: 236; sh: 64; makefile: 25; xml: 8
file content (139 lines) | stat: -rw-r--r-- 4,127 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*=========================================================================

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "XML/vtkXMLKWOpenFilePropertiesWriter.h"

#include "vtkKWOpenFileProperties.h"
#include "vtkObjectFactory.h"
#include "vtkKWOpenFileProperties.h"
#include "vtkXMLDataElement.h"

#include <vtksys/SystemTools.hxx>

vtkStandardNewMacro(vtkXMLKWOpenFilePropertiesWriter);
vtkCxxRevisionMacro(vtkXMLKWOpenFilePropertiesWriter, "$Revision: 1.5 $");

//----------------------------------------------------------------------------
vtkXMLKWOpenFilePropertiesWriter::vtkXMLKWOpenFilePropertiesWriter()
{
  this->DiscardFilePatternDirectory = 0;
}

//----------------------------------------------------------------------------
const char* vtkXMLKWOpenFilePropertiesWriter::GetRootElementName()
{
  return "KWOpenFileProperties";
}

//----------------------------------------------------------------------------
int vtkXMLKWOpenFilePropertiesWriter::AddAttributes(vtkXMLDataElement *elem)
{
  if (!this->Superclass::AddAttributes(elem))
    {
    return 0;
    }

  vtkKWOpenFileProperties *obj = vtkKWOpenFileProperties::SafeDownCast(this->Object);
  if (!obj)
    {
    vtkWarningMacro(<< "The KWOpenFileProperties is not set!");
    return 0;
    }

  int ibuffer3[3], ival, i;

  elem->SetVectorAttribute("Spacing", 3, obj->GetSpacing());

  elem->SetVectorAttribute("Origin", 3, obj->GetOrigin());

  elem->SetAttribute("DistanceUnits", obj->GetDistanceUnits());

  for (i = 0; i < obj->GetNumberOfScalarComponents(); i++)
    {
    char scalarunits[256];
    sprintf(scalarunits, "ScalarUnits%d", i);
    elem->SetAttribute(scalarunits, obj->GetScalarUnits(i));
    }

  elem->SetIntAttribute("ScalarType", obj->GetScalarType());

  elem->SetVectorAttribute("WholeExtent", 6, obj->GetWholeExtent());

  elem->SetIntAttribute("NumberOfScalarComponents",
                        obj->GetNumberOfScalarComponents());
  
  elem->SetIntAttribute("IndependentComponents", 
                        obj->GetIndependentComponents());

  if (obj->GetSliceAxis() != 
      vtkKWOpenFileProperties::AxisOrientationUnknown &&
      obj->GetRowAxis() != 
      vtkKWOpenFileProperties::AxisOrientationUnknown &&
      obj->GetColumnAxis() != 
      vtkKWOpenFileProperties::AxisOrientationUnknown)
    {
    ibuffer3[0] = obj->GetSliceAxis();
    ibuffer3[1] = obj->GetRowAxis();
    ibuffer3[2] = obj->GetColumnAxis();
    elem->SetVectorAttribute("FileOrientation", 3, ibuffer3);
    }

  if (obj->GetDataByteOrder() != 
      vtkKWOpenFileProperties::DataByteOrderUnknown)
    {
    ival = (obj->GetDataByteOrder() == 
            vtkKWOpenFileProperties::DataByteOrderBigEndian ? 1 : 0);
    }
  else
    {
#ifdef VTK_WORDS_BIGENDIAN
    ival = 1;
#else
    ival = 0;
#endif
    }
  elem->SetIntAttribute("BigEndianFlag", ival);

  if (obj->GetFilePattern())
    {
    if (this->DiscardFilePatternDirectory)
      {
      vtksys_stl::string basename = 
        vtksys::SystemTools::GetFilenameName(obj->GetFilePattern());
      elem->SetAttribute("FilePattern", basename.c_str());
      }
    else
      {
      elem->SetAttribute("FilePattern", obj->GetFilePattern());
      }
    }

  if (obj->GetFileDimensionality())
    {
    elem->SetIntAttribute("FileDimensionality", 
                          obj->GetFileDimensionality());
    }

  elem->SetIntAttribute("Scope", obj->GetScope());
  
  return 1;
}


//----------------------------------------------------------------------------
void vtkXMLKWOpenFilePropertiesWriter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "DiscardFilePatternDirectory: "
     << (this->DiscardFilePatternDirectory ? "On" : "Off") << endl;
}