vtkGenericVertexAttributeMapping.cxx 5.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkGenericVertexAttributeMapping.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.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 "vtkGenericVertexAttributeMapping.h"

#include "vtkObjectFactory.h"
18
19
#include <string>
#include <vector>
20

21
22
#include <vtksys/ios/sstream>

23
24
25
26
27
class vtkGenericVertexAttributeMapping::vtkInternal
{
public:
  struct vtkInfo
    {
28
29
    std::string AttributeName;
    std::string ArrayName;
30
31
    int FieldAssociation;
    int Component;
32
    int TextureUnit;
33
34
    };

35
  typedef std::vector<vtkInfo> VectorType;
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
  VectorType Mappings;
};

vtkStandardNewMacro(vtkGenericVertexAttributeMapping);
//----------------------------------------------------------------------------
vtkGenericVertexAttributeMapping::vtkGenericVertexAttributeMapping()
{
  this->Internal = new vtkInternal();
}

//----------------------------------------------------------------------------
vtkGenericVertexAttributeMapping::~vtkGenericVertexAttributeMapping()
{
  delete this->Internal;
}

//----------------------------------------------------------------------------
void vtkGenericVertexAttributeMapping::AddMapping(
  const char* attributeName, const char* arrayName, int fieldAssociation,
  int component)
{
  if (!attributeName || !arrayName)
    {
    vtkErrorMacro("arrayName and attributeName cannot be null.");
    return;
    }

  if (this->RemoveMapping(attributeName))
    {
Sean McBride's avatar
Sean McBride committed
65
    vtkWarningMacro("Replacing existing mapping for attribute "
66
67
68
69
70
71
72
73
      << attributeName);
    }

  vtkInternal::vtkInfo info;
  info.AttributeName = attributeName;
  info.ArrayName = arrayName;
  info.FieldAssociation = fieldAssociation;
  info.Component = component;
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  info.TextureUnit = -1;
  this->Internal->Mappings.push_back(info);
}

//----------------------------------------------------------------------------
void vtkGenericVertexAttributeMapping::AddMapping(
  int unit, const char* arrayName, int fieldAssociation,
  int component)
{
  vtksys_ios::ostringstream attributeName;
  attributeName << unit;

  if (this->RemoveMapping(attributeName.str().c_str()))
    {
Sean McBride's avatar
Sean McBride committed
88
    vtkWarningMacro("Replacing existing mapping for attribute "
89
      << attributeName.str().c_str());
90
91
92
93
94
95
96
97
    }

  vtkInternal::vtkInfo info;
  info.AttributeName = attributeName.str().c_str();
  info.ArrayName = arrayName;
  info.FieldAssociation = fieldAssociation;
  info.Component = component;
  info.TextureUnit = unit;
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
  this->Internal->Mappings.push_back(info);
}

//----------------------------------------------------------------------------
bool vtkGenericVertexAttributeMapping::RemoveMapping(const char* attributeName)
{
  vtkInternal::VectorType::iterator iter;
  for (iter=this->Internal->Mappings.begin();
    iter != this->Internal->Mappings.end(); ++iter)
    {
    if (iter->AttributeName == attributeName)
      {
      this->Internal->Mappings.erase(iter);
      return true;
      }
    }
  return false;
}


//----------------------------------------------------------------------------
void vtkGenericVertexAttributeMapping::RemoveAllMappings()
{
  this->Internal->Mappings.clear();
}

//----------------------------------------------------------------------------
unsigned int vtkGenericVertexAttributeMapping::GetNumberOfMappings()
{
127
  return static_cast<unsigned int>(this->Internal->Mappings.size());
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
}

//----------------------------------------------------------------------------
const char* vtkGenericVertexAttributeMapping::GetAttributeName(unsigned int index)
{
  if (index >= this->Internal->Mappings.size())
    {
    vtkErrorMacro("Invalid index " << index);
    return 0;
    }
  return this->Internal->Mappings[index].AttributeName.c_str();
}

//----------------------------------------------------------------------------
const char* vtkGenericVertexAttributeMapping::GetArrayName(unsigned int index)
{
  if (index >= this->Internal->Mappings.size())
    {
    vtkErrorMacro("Invalid index " << index);
    return 0;
    }
  return this->Internal->Mappings[index].ArrayName.c_str();
}

//----------------------------------------------------------------------------
int vtkGenericVertexAttributeMapping::GetFieldAssociation(unsigned int index)
{
  if (index >= this->Internal->Mappings.size())
    {
    vtkErrorMacro("Invalid index " << index);
    return 0;
    }
  return this->Internal->Mappings[index].FieldAssociation;
}

//----------------------------------------------------------------------------
int vtkGenericVertexAttributeMapping::GetComponent(unsigned int index)
{
  if (index >= this->Internal->Mappings.size())
    {
    vtkErrorMacro("Invalid index " << index);
    return 0;
    }
  return this->Internal->Mappings[index].Component;
}

174
175
176
177
178
179
180
181
182
183
184
//----------------------------------------------------------------------------
int vtkGenericVertexAttributeMapping::GetTextureUnit(unsigned int index)
{
  if (index >= this->Internal->Mappings.size())
    {
    vtkErrorMacro("Invalid index " << index);
    return 0;
    }
  return this->Internal->Mappings[index].TextureUnit;
}

185
186
187
188
189
190
191
192
193
194
195
196
197
//----------------------------------------------------------------------------
void vtkGenericVertexAttributeMapping::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
   vtkInternal::VectorType::iterator iter;
  for (iter=this->Internal->Mappings.begin();
    iter != this->Internal->Mappings.end(); ++iter)
    {
    os << indent << "Mapping: "
      << iter->AttributeName.c_str() << ", "
      << iter->ArrayName.c_str() << ", "
      << iter->FieldAssociation << ", "
      << iter->Component << endl;
198
    }
199
200
}