Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Scott Wittenburg
VTK
Commits
2cda3ff7
Commit
2cda3ff7
authored
Dec 28, 2013
by
Utkarsh Ayachit
⛰
Committed by
Code Review
Dec 28, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge topic 'add_naming_conventions' into master
13b31513
Adding new naming modes to vtkSplitColumnComponents.
parents
8ffb6a1c
13b31513
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
18 deletions
+195
-18
Filters/General/Testing/Cxx/CMakeLists.txt
Filters/General/Testing/Cxx/CMakeLists.txt
+6
-5
Filters/General/Testing/Cxx/TestTableSplitColumnComponents.cxx
...rs/General/Testing/Cxx/TestTableSplitColumnComponents.cxx
+39
-2
Filters/General/vtkSplitColumnComponents.cxx
Filters/General/vtkSplitColumnComponents.cxx
+113
-9
Filters/General/vtkSplitColumnComponents.h
Filters/General/vtkSplitColumnComponents.h
+37
-2
No files found.
Filters/General/Testing/Cxx/CMakeLists.txt
View file @
2cda3ff7
vtk_add_test_cxx
(
TestGraphWeightEuclideanDistanceFilter.cxx,NO_VALID
BoxClipPolyData.cxx
BoxClipTetrahedra.cxx
BoxClipTriangulate.cxx,NO_VALID
BoxClipTriangulateAndInterpolate.cxx
BoxClipTriangulate.cxx,NO_VALID
TestAppendPoints.cxx,NO_VALID
TestBooleanOperationPolyDataFilter.cxx
TestBooleanOperationPolyDataFilter2.cxx
Test
ContourTriangulato
r.cxx
Test
BooleanOperationPolyDataFilte
r.cxx
TestContourTriangulatorCutter.cxx
TestContourTriangulator.cxx
TestContourTriangulatorMarching.cxx
TestDeformPointSet.cxx
TestDensifyPolyData.cxx,-E15
TestDistancePolyDataFilter.cxx
TestGraphWeightEuclideanDistanceFilter.cxx,NO_VALID
TestImageDataToPointSet.cxx,NO_VALID
TestIntersectionPolyDataFilter.cxx
TestIntersectionPolyDataFilter2.cxx,NO_VALID
TestIntersectionPolyDataFilter.cxx
TestRectilinearGridToPointSet.cxx,NO_VALID
TestReflectionFilter.cxx,NO_VALID
TestTableSplitColumnComponents.cxx,NO_VALID
TestTransformFilter.cxx,NO_VALID
TestTransformPolyDataFilter.cxx,NO_VALID
TestUncertaintyTubeFilter.cxx
...
...
Filters/General/Testing/Cxx/TestTableSplitColumnComponents.cxx
View file @
2cda3ff7
...
...
@@ -55,7 +55,7 @@ int TestTableSplitColumnComponents(int, char*[])
{
vtkGenericWarningMacro
(
<<
"Incorrect column count: "
<<
out
->
GetNumberOfColumns
());
return
1
;
return
EXIT_FAILURE
;
}
vtkIntArray
*
arrays
[
4
];
arrays
[
0
]
=
vtkIntArray
::
SafeDownCast
(
out
->
GetColumn
(
0
));
...
...
@@ -65,7 +65,7 @@ int TestTableSplitColumnComponents(int, char*[])
if
(
arrays
[
0
]
==
0
||
arrays
[
1
]
==
0
||
arrays
[
2
]
==
0
||
arrays
[
3
]
==
0
)
{
vtkGenericWarningMacro
(
<<
"One of the output arrays was zero - type change?"
);
return
1
;
return
EXIT_FAILURE
;
}
for
(
int
i
=
0
;
i
<
5
;
++
i
)
...
...
@@ -80,5 +80,42 @@ int TestTableSplitColumnComponents(int, char*[])
}
}
// Test naming modes.
if
(
strcmp
(
arrays
[
1
]
->
GetName
(),
"Multi (0)"
)
!=
0
)
{
vtkGenericWarningMacro
(
"Incorrect name. NamingMode not being respected correctly."
);
return
EXIT_FAILURE
;
}
split
->
SetNamingModeToNumberWithUnderscores
();
split
->
Update
();
out
=
split
->
GetOutput
(
0
);
arrays
[
1
]
=
vtkIntArray
::
SafeDownCast
(
out
->
GetColumn
(
1
));
if
(
strcmp
(
arrays
[
1
]
->
GetName
(),
"Multi_0"
)
!=
0
)
{
vtkGenericWarningMacro
(
"Incorrect name. NamingMode not being respected correctly."
);
return
EXIT_FAILURE
;
}
split
->
SetNamingModeToNamesWithParens
();
split
->
Update
();
out
=
split
->
GetOutput
(
0
);
arrays
[
1
]
=
vtkIntArray
::
SafeDownCast
(
out
->
GetColumn
(
1
));
if
(
strcmp
(
arrays
[
1
]
->
GetName
(),
"Multi (X)"
)
!=
0
)
{
vtkGenericWarningMacro
(
"Incorrect name. NamingMode not being respected correctly."
);
return
EXIT_FAILURE
;
}
split
->
SetNamingModeToNamesWithUnderscores
();
split
->
Update
();
out
=
split
->
GetOutput
(
0
);
arrays
[
1
]
=
vtkIntArray
::
SafeDownCast
(
out
->
GetColumn
(
1
));
if
(
strcmp
(
arrays
[
1
]
->
GetName
(),
"Multi_X"
)
!=
0
)
{
vtkGenericWarningMacro
(
"Incorrect name. NamingMode not being respected correctly."
);
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
}
Filters/General/vtkSplitColumnComponents.cxx
View file @
2cda3ff7
...
...
@@ -12,13 +12,13 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSplitColumnComponents.h"
#include "vtkAbstractArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtk
AbstractArray
.h"
#include "vtk
StdString
.h"
#include "vtkTable.h"
#include "vtksys/ios/sstream"
...
...
@@ -31,6 +31,7 @@ vtkSplitColumnComponents::vtkSplitColumnComponents()
this
->
SetNumberOfInputPorts
(
1
);
this
->
SetNumberOfOutputPorts
(
1
);
this
->
CalculateMagnitudes
=
true
;
this
->
NamingMode
=
NUMBERS_WITH_PARENS
;
}
//---------------------------------------------------------------------------
...
...
@@ -91,7 +92,6 @@ int vtkSplitColumnComponents::RequestData(
for
(
int
i
=
0
;
i
<
table
->
GetNumberOfColumns
();
++
i
)
{
vtkAbstractArray
*
col
=
table
->
GetColumn
(
i
);
char
*
name
=
col
->
GetName
();
int
components
=
col
->
GetNumberOfComponents
();
if
(
components
==
1
)
{
...
...
@@ -103,10 +103,9 @@ int vtkSplitColumnComponents::RequestData(
int
colSize
=
col
->
GetNumberOfTuples
();
for
(
int
j
=
0
;
j
<
components
;
++
j
)
{
vtksys_ios
::
ostringstream
ostr
;
ostr
<<
name
<<
" ("
<<
j
<<
")"
;
vtkStdString
component_label
=
this
->
GetComponentLabel
(
col
,
j
);
vtkAbstractArray
*
newCol
=
vtkAbstractArray
::
CreateArray
(
col
->
GetDataType
());
newCol
->
SetName
(
ostr
.
str
()
.
c_str
());
newCol
->
SetName
(
component_label
.
c_str
());
newCol
->
SetNumberOfTuples
(
colSize
);
// Now copy the components into their new columns
switch
(
col
->
GetDataType
())
...
...
@@ -123,10 +122,10 @@ int vtkSplitColumnComponents::RequestData(
// Add a magnitude column and calculate values if requested
if
(
this
->
CalculateMagnitudes
&&
col
->
IsA
(
"vtkDataArray"
))
{
vtk
sys_ios
::
ostringstream
ostr
;
ostr
<<
name
<<
" (M
agnitude)
"
;
vtk
StdString
component_label
=
this
->
GetComponentLabel
(
col
,
-
1
/* for m
agnitude
*/
);
vtkAbstractArray
*
newCol
=
vtkAbstractArray
::
CreateArray
(
col
->
GetDataType
());
newCol
->
SetName
(
ostr
.
str
()
.
c_str
());
newCol
->
SetName
(
component_label
.
c_str
());
newCol
->
SetNumberOfTuples
(
colSize
);
// Now calculate the magnitude column
switch
(
col
->
GetDataType
())
...
...
@@ -146,9 +145,114 @@ int vtkSplitColumnComponents::RequestData(
return
1
;
}
namespace
{
//----------------------------------------------------------------------------
std
::
string
vtkDefaultComponentName
(
int
componentNumber
,
int
componentCount
)
{
if
(
componentCount
<=
1
)
{
return
""
;
}
else
if
(
componentNumber
==
-
1
)
{
return
"Magnitude"
;
}
else
if
(
componentCount
<=
3
&&
componentNumber
<
3
)
{
const
char
*
titles
[]
=
{
"X"
,
"Y"
,
"Z"
};
return
titles
[
componentNumber
];
}
else
if
(
componentCount
==
6
)
{
const
char
*
titles
[]
=
{
"XX"
,
"YY"
,
"ZZ"
,
"XY"
,
"YZ"
,
"XZ"
};
// Assume this is a symmetric matrix.
return
titles
[
componentNumber
];
}
else
{
std
::
ostringstream
buffer
;
buffer
<<
componentNumber
;
return
buffer
.
str
();
}
}
std
::
string
vtkGetComponentName
(
vtkAbstractArray
*
array
,
int
component_no
)
{
const
char
*
name
=
array
->
GetComponentName
(
component_no
);
if
(
name
)
{
return
name
;
}
return
vtkDefaultComponentName
(
component_no
,
array
->
GetNumberOfComponents
());
}
};
//---------------------------------------------------------------------------
vtkStdString
vtkSplitColumnComponents
::
GetComponentLabel
(
vtkAbstractArray
*
array
,
int
component_no
)
{
std
::
ostringstream
stream
;
switch
(
this
->
NamingMode
)
{
case
NUMBERS_WITH_PARENS
:
stream
<<
array
->
GetName
()
<<
" ("
;
if
(
component_no
==
-
1
)
{
stream
<<
"Magnitude)"
;
}
else
{
stream
<<
component_no
<<
")"
;
}
break
;
case
NUMBERS_WITH_UNDERSCORES
:
stream
<<
array
->
GetName
()
<<
"_"
;
if
(
component_no
==
-
1
)
{
stream
<<
"Magnitude"
;
}
else
{
stream
<<
component_no
;
}
break
;
case
NAMES_WITH_PARENS
:
stream
<<
array
->
GetName
()
<<
" ("
<<
vtkGetComponentName
(
array
,
component_no
).
c_str
()
<<
")"
;
break
;
case
NAMES_WITH_UNDERSCORES
:
default:
stream
<<
array
->
GetName
()
<<
"_"
<<
vtkGetComponentName
(
array
,
component_no
).
c_str
();;
break
;
}
return
stream
.
str
();
}
//---------------------------------------------------------------------------
void
vtkSplitColumnComponents
::
PrintSelf
(
ostream
&
os
,
vtkIndent
indent
)
{
this
->
Superclass
::
PrintSelf
(
os
,
indent
);
os
<<
indent
<<
"CalculateMagnitudes: "
<<
this
->
CalculateMagnitudes
<<
endl
;
os
<<
indent
<<
"NamingMode: "
;
switch
(
this
->
NamingMode
)
{
case
NAMES_WITH_UNDERSCORES
:
os
<<
"NAMES_WITH_UNDERSCORES"
<<
endl
;
break
;
case
NAMES_WITH_PARENS
:
os
<<
"NAMES_WITH_PARENS"
<<
endl
;
break
;
case
NUMBERS_WITH_UNDERSCORES
:
os
<<
"NUMBERS_WITH_UNDERSCORES"
<<
endl
;
break
;
case
NUMBERS_WITH_PARENS
:
os
<<
"NUMBERS_WITH_PARENS"
<<
endl
;
break
;
default:
os
<<
"INVALID"
<<
endl
;
}
}
Filters/General/vtkSplitColumnComponents.h
View file @
2cda3ff7
...
...
@@ -22,8 +22,14 @@
// .SECTION Description
// Splits any columns in a table that have more than one component into
// individual columns. Single component columns are passed through without
// any data duplication. So if column names "Points" had three components
// this column would be split into "Points (0)", "Points (1)" and Points (2)".
// any data duplication.
// NamingMode can be used to control how columns with multiple components are
// labelled in the output, e.g., if column names "Points" had three components
// this column would be split into "Points (0)", "Points (1)", and Points (2)"
// when NamingMode is NUMBERS_WITH_PARENS, into Points_0, Points_1, and Points_2
// when NamingMode is NUMBERS_WITH_UNDERSCORES, into "Points (X)", "Points (Y)",
// and "Points (Z)" when NamingMode is NAMES_WITH_PARENS, and into Points_X,
// Points_Y, and Points_Z when NamingMode is NAMES_WITH_UNDERSCORES.
#ifndef __vtkSplitColumnComponents_h
#define __vtkSplitColumnComponents_h
...
...
@@ -31,6 +37,7 @@
#include "vtkFiltersGeneralModule.h" // For export macro
#include "vtkTableAlgorithm.h"
class
vtkStdString
;
class
VTKFILTERSGENERAL_EXPORT
vtkSplitColumnComponents
:
public
vtkTableAlgorithm
{
public:
...
...
@@ -45,10 +52,37 @@ public:
vtkSetMacro
(
CalculateMagnitudes
,
bool
);
vtkGetMacro
(
CalculateMagnitudes
,
bool
);
enum
{
NUMBERS_WITH_PARENS
=
0
,
// e.g Points (0)
NAMES_WITH_PARENS
=
1
,
// e.g. Points (X)
NUMBERS_WITH_UNDERSCORES
=
2
,
// e.g. Points_0
NAMES_WITH_UNDERSCORES
=
3
// e.g. Points_X
};
// Description:
// Get/Set the array naming mode.
// Description is NUMBERS_WITH_PARENS.
vtkSetClampMacro
(
NamingMode
,
int
,
NUMBERS_WITH_PARENS
,
NAMES_WITH_UNDERSCORES
);
void
SetNamingModeToNumberWithParens
()
{
this
->
SetNamingMode
(
NUMBERS_WITH_PARENS
);
}
void
SetNamingModeToNumberWithUnderscores
()
{
this
->
SetNamingMode
(
NUMBERS_WITH_UNDERSCORES
);
}
void
SetNamingModeToNamesWithParens
()
{
this
->
SetNamingMode
(
NAMES_WITH_PARENS
);
}
void
SetNamingModeToNamesWithUnderscores
()
{
this
->
SetNamingMode
(
NAMES_WITH_UNDERSCORES
);
}
vtkGetMacro
(
NamingMode
,
int
);
protected:
vtkSplitColumnComponents
();
~
vtkSplitColumnComponents
();
// Description:
// Returns the label to use for the specific component in the array based on
// this->NamingMode. Use component_no==-1 for magnitude.
vtkStdString
GetComponentLabel
(
vtkAbstractArray
*
array
,
int
component_no
);
bool
CalculateMagnitudes
;
int
RequestData
(
...
...
@@ -56,6 +90,7 @@ protected:
vtkInformationVector
**
,
vtkInformationVector
*
);
int
NamingMode
;
private:
vtkSplitColumnComponents
(
const
vtkSplitColumnComponents
&
);
// Not implemented
void
operator
=
(
const
vtkSplitColumnComponents
&
);
// Not implemented
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment