Commit 494fc364 authored by Jeff Baumes's avatar Jeff Baumes
Browse files

ENH: Initial version of Infovis kit. Also added some classes to vtkCommon,...

ENH: Initial version of Infovis kit.  Also added some classes to vtkCommon, vtkFiltering, vtkRendering, vtkIO, and added freerange to Utilities.
parent 7e73bc04
......@@ -927,6 +927,7 @@ SUBDIRS(
Common
Filtering
Imaging
Infovis
Graphics
GenericFiltering
IO)
......@@ -960,7 +961,7 @@ IF(BUILD_TESTING)
MAKE_DIRECTORY(${VTK_BINARY_DIR}/Testing/Temporary)
# Build scripts to convert tcl tests to python
SUBDIRS(Utilities/vtkTclTest2Py)
SUBDIRS(Common/Testing Filtering/Testing Graphics/Testing GenericFiltering/Testing Imaging/Testing
SUBDIRS(Common/Testing Filtering/Testing Infovis/Testing Graphics/Testing GenericFiltering/Testing Imaging/Testing
IO/Testing)
IF(VTK_USE_RENDERING)
SUBDIRS(Rendering/Testing)
......@@ -1430,6 +1431,7 @@ IF(NOT VTK_INSTALL_NO_DEVELOPMENT)
${VTK_BINARY_DIR}/vtkFilteringInstantiator.h
${VTK_BINARY_DIR}/vtkIOInstantiator.h
${VTK_BINARY_DIR}/vtkImagingInstantiator.h
${VTK_BINARY_DIR}/vtkInfovisInstantiator.h
${VTK_BINARY_DIR}/vtkGraphicsInstantiator.h
${VTK_BINARY_DIR}/vtkGenericFilteringInstantiator.h
${VTK_CMAKE_DIR}/vtkMakeInstantiator.cmake
......
......@@ -147,6 +147,8 @@ vtkUnsignedCharArray.cxx
vtkUnsignedIntArray.cxx
vtkUnsignedLongArray.cxx
vtkUnsignedShortArray.cxx
vtkVariant.cxx
vtkVariantArray.cxx
vtkVersion.cxx
vtkVoidArray.cxx
vtkWarpTransform.cxx
......@@ -258,6 +260,8 @@ SET_SOURCE_FILES_PROPERTIES(
vtkSmartPointerBase.cxx
vtkStdString.cxx
vtkTimeStamp.cxx
vtkVariant.cxx
vtkVariantArray.cxx
WRAP_EXCLUDE
)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkVariant.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 "vtkVariant.h"
#include "vtkStdString.h"
#include "vtkArrayIteratorIncludes.h"
#include "vtkAbstractArray.h"
#include "vtkDataArray.h"
#include "vtkVariantArray.h"
#include "vtkType.h"
#include "vtkSetGet.h"
#include "vtkObjectBase.h"
#include "vtkStringArray.h"
#include "vtksys/ios/sstream"
vtkVariant::vtkVariant()
{
this->Valid = 0;
this->Type = 0;
}
vtkVariant::vtkVariant(const vtkVariant & other)
{
this->Valid = other.Valid;
this->Type = other.Type;
this->Data = other.Data;
if (this->Valid)
{
switch (other.Type)
{
case VTK_STRING:
this->Data.String = new vtkStdString(*other.Data.String);
break;
case VTK_OBJECT:
this->Data.VTKObject->Register(0);
break;
}
}
}
const vtkVariant & vtkVariant::operator= (const vtkVariant & other)
{
// First delete current variant item.
if (this->Valid)
{
switch (this->Type)
{
case VTK_STRING:
delete this->Data.String;
break;
case VTK_OBJECT:
this->Data.VTKObject->Delete();
break;
}
}
// Then set the appropriate value.
this->Valid = other.Valid;
this->Type = other.Type;
this->Data = other.Data;
if (this->Valid)
{
switch (other.Type)
{
case VTK_STRING:
this->Data.String = new vtkStdString(*other.Data.String);
break;
case VTK_OBJECT:
this->Data.VTKObject->Register(0);
break;
}
}
return *this;
}
vtkVariant::~vtkVariant()
{
if (this->Valid)
{
switch (this->Type)
{
case VTK_STRING:
delete this->Data.String;
break;
case VTK_OBJECT:
this->Data.VTKObject->Delete();
break;
}
}
}
vtkVariant::vtkVariant(vtkStdString value)
{
this->Data.String = new vtkStdString(value);
this->Valid = 1;
this->Type = VTK_STRING;
}
vtkVariant::vtkVariant(const char* value)
{
this->Data.String = new vtkStdString(value);
this->Valid = 1;
this->Type = VTK_STRING;
}
vtkVariant::vtkVariant(float value)
{
this->Data.Float = value;
this->Valid = 1;
this->Type = VTK_FLOAT;
}
vtkVariant::vtkVariant(double value)
{
this->Data.Double = value;
this->Valid = 1;
this->Type = VTK_DOUBLE;
}
vtkVariant::vtkVariant(int value)
{
this->Data.Int = value;
this->Valid = 1;
this->Type = VTK_INT;
}
#if defined(VTK_TYPE_USE___INT64)
vtkVariant::vtkVariant(__int64 value)
{
this->Data.__Int64 = value;
this->Valid = 1;
this->Type = VTK___INT64;
}
vtkVariant::vtkVariant(unsigned __int64 value)
{
this->Data.Unsigned__Int64 = value;
this->Valid = 1;
this->Type = VTK_UNSIGNED___INT64;
}
#endif
#if defined(VTK_TYPE_USE_LONG_LONG)
vtkVariant::vtkVariant(long long value)
{
this->Data.LongLong = value;
this->Valid = 1;
this->Type = VTK_LONG_LONG;
}
vtkVariant::vtkVariant(unsigned long long value)
{
this->Data.UnsignedLongLong = value;
this->Valid = 1;
this->Type = VTK_UNSIGNED_LONG_LONG;
}
#endif
vtkVariant::vtkVariant(vtkObjectBase* value)
{
value->Register(0);
this->Data.VTKObject = value;
this->Valid = 1;
this->Type = VTK_OBJECT;
}
bool vtkVariant::IsValid() const
{
return this->Valid != 0;
}
bool vtkVariant::IsString() const
{
return this->Type == VTK_STRING;
}
bool vtkVariant::IsNumeric() const
{
return this->IsFloat()
|| this->IsDouble()
|| this->IsInt()
|| this->Is__Int64()
|| this->IsUnsigned__Int64()
|| this->IsLongLong()
|| this->IsUnsignedLongLong();
}
bool vtkVariant::IsFloat() const
{
return this->Type == VTK_FLOAT;
}
bool vtkVariant::IsDouble() const
{
return this->Type == VTK_DOUBLE;
}
bool vtkVariant::IsInt() const
{
return this->Type == VTK_INT;
}
bool vtkVariant::Is__Int64() const
{
return this->Type == VTK___INT64;
}
bool vtkVariant::IsUnsigned__Int64() const
{
return this->Type == VTK_UNSIGNED___INT64;
}
bool vtkVariant::IsLongLong() const
{
return this->Type == VTK_LONG_LONG;
}
bool vtkVariant::IsUnsignedLongLong() const
{
return this->Type == VTK_UNSIGNED_LONG_LONG;
}
bool vtkVariant::IsVTKObject() const
{
return this->Type == VTK_OBJECT;
}
bool vtkVariant::IsArray() const
{
return this->Type == VTK_OBJECT
&& this->Valid
&& this->Data.VTKObject->IsA("vtkAbstractArray");
}
unsigned int vtkVariant::GetType() const
{
return this->Type;
}
const char* vtkVariant::GetTypeAsString() const
{
if (this->Type == VTK_OBJECT && this->Valid)
{
return this->Data.VTKObject->GetClassName();
}
return vtkImageScalarTypeNameMacro(this->Type);
}
vtkStdString vtkVariant::ToString() const
{
if (!this->IsValid())
{
return vtkStdString();
}
if (this->IsString())
{
return vtkStdString(this->Data.String->c_str());
}
if (this->IsFloat())
{
vtksys_ios::ostringstream ostr;
ostr << this->Data.Float;
return vtkStdString(ostr.str());
}
if (this->IsDouble())
{
vtksys_ios::ostringstream ostr;
ostr << this->Data.Double;
return vtkStdString(ostr.str());
}
if (this->IsInt())
{
vtksys_ios::ostringstream ostr;
ostr << this->Data.Int;
return vtkStdString(ostr.str());
}
#if defined(VTK_TYPE_USE___INT64)
if (this->Is__Int64())
{
vtksys_ios::ostringstream ostr;
ostr << this->Data.__Int64;
return vtkStdString(ostr.str());
}
#endif
if (this->IsArray())
{
vtkAbstractArray* arr = vtkAbstractArray::SafeDownCast(this->Data.VTKObject);
vtkArrayIterator* iter = arr->NewIterator();
vtkStdString str;
switch(arr->GetDataType())
{
vtkArrayIteratorTemplateMacro(
str = this->ArrayToString(static_cast<VTK_TT*>(iter)));
}
iter->Delete();
return str;
}
return vtkStdString();
}
float vtkVariant::ToFloat(bool* valid) const
{
return this->ToNumeric<float>(valid);
}
double vtkVariant::ToDouble(bool* valid) const
{
return this->ToNumeric<double>(valid);
}
int vtkVariant::ToInt(bool* valid) const
{
return this->ToNumeric<int>(valid);
}
#if defined(VTK_TYPE_USE___INT64)
__int64 vtkVariant::To__Int64(bool* valid) const
{
return this->ToNumeric<__int64>(valid);
}
unsigned __int64 vtkVariant::ToUnsigned__Int64(bool* valid) const
{
return this->ToNumeric<unsigned __int64>(valid);
}
#endif
#if defined(VTK_TYPE_USE_LONG_LONG)
long long vtkVariant::ToLongLong(bool* valid) const
{
return this->ToNumeric<long long>(valid);
}
unsigned long long vtkVariant::ToUnsignedLongLong(bool* valid) const
{
return this->ToNumeric<unsigned long long>(valid);
}
#endif
vtkObjectBase* vtkVariant::ToVTKObject() const
{
if (this->IsVTKObject())
{
return this->Data.VTKObject;
}
return 0;
}
vtkAbstractArray* vtkVariant::ToArray() const
{
if (this->IsArray())
{
return vtkAbstractArray::SafeDownCast(this->Data.VTKObject);
}
return 0;
}
ostream& operator << (ostream& out, vtkVariant v)
{
out << v.ToString();
return out;
}
template <typename T>
vtkStdString vtkVariant::ArrayToString(T* it) const
{
vtkIdType maxInd = it->GetNumberOfValues();
vtksys_ios::ostringstream ostr;
for (vtkIdType i = 0; i < maxInd; i++)
{
if (i > 0)
{
ostr << " ";
}
ostr << it->GetValue(i);
}
return ostr.str();
}
template <typename T>
T vtkVariantStringToNumeric(vtkStdString str, bool* valid, T* vtkNotUsed(ignored) = 0)
{
vtkstd::istringstream vstr(str);
T data;
vstr >> data;
// Check for a valid result
if (valid)
{
*valid = ((vstr.rdstate() & ios::badbit) == 0
&& (vstr.rdstate() & ios::failbit) == 0);
//*valid = (vstr.rdstate() == ios::goodbit);
}
return data;
}
template <typename T>
T vtkVariant::ToNumeric(bool* valid, T*) const
{
if (valid)
{
*valid = true;
}
if (this->IsString())
{
return vtkVariantStringToNumeric<T>(* this->Data.String, valid);
}
if (this->IsFloat())
{
return static_cast<T>(this->Data.Float);
}
if (this->IsDouble())
{
return static_cast<T>(this->Data.Double);
}
if (this->IsInt())
{
return static_cast<T>(this->Data.Int);
}
#if defined(VTK_TYPE_USE___INT64)
if (this->Is__Int64())
{
return static_cast<T>(this->Data.__Int64);
}
if (this->IsUnsigned__Int64())
{
return static_cast<T>(this->Data.Unsigned__Int64);
}
#endif
#if defined(VTK_TYPE_USE_LONG_LONG)
if (this->IsLongLong())
{
return static_cast<T>(this->Data.LongLong);
}
if (this->IsUnsignedLongLong())
{
return static_cast<T>(this->Data.UnsignedLongLong);
}
#endif
// For arrays, convert the first value to the appropriate type.
if (this->IsArray())
{
if (this->Data.VTKObject->IsA("vtkDataArray"))
{
// Note: This are not the best conversion.
// We covert the first value to double, then
// cast it back to the appropriate numeric type.
vtkDataArray* da = vtkDataArray::SafeDownCast(this->Data.VTKObject);
return static_cast<T>(da->GetTuple1(0));
}
if (this->Data.VTKObject->IsA("vtkVariantArray"))
{
// Note: This are not the best conversion.
// We covert the first value to double, then
// cast it back to the appropriate numeric type.
vtkVariantArray* va = vtkVariantArray::SafeDownCast(this->Data.VTKObject);
return static_cast<T>(va->GetValue(0).ToDouble());
}
if (this->Data.VTKObject->IsA("vtkStringArray"))
{
vtkStringArray* sa = vtkStringArray::SafeDownCast(this->Data.VTKObject);
return vtkVariantStringToNumeric<T>(sa->GetValue(0), valid);
}
}
if (valid)
{
*valid = false;
}
return static_cast<T>(0);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkVariant.h
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.
=========================================================================*/
// .NAME vtkVariant - A atomic type representing the union of many types
//
// .SECTION Description
//
// .SECTION Thanks
// Thanks to Patricia Crossno, Ken Moreland, Andrew Wilson and Brian Wylie from
// Sandia National Laboratories for their help in developing this class.
#ifndef __vtkVariant_h
#define __vtkVariant_h
#include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
#include "vtkSystemIncludes.h" // To define ostream
//
// The following should be eventually placed in vtkType.h
//
/* These types are required by vtkVariant and vtkVariantArray */
#define VTK_VARIANT 20
#define VTK_OBJECT 21
//
// The following should be eventually placed in vtkSetGet.h
//
// This is same as extended template macro with additional cases for
// VTK_VARIANT, and VTK_OBJECT.
#define vtkExtraExtendedTemplateMacro(call) \
vtExtendedTemplateMacro(call); \
vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call) \
vtkTemplateMacroCase(VTK_OBJECT, vtkObjectBase, call)
// This is same as Iterator Template macro with additional case for VTK_VARIANT
#define vtkExtendedArrayIteratorTemplateMacro(call) \
vtkArrayIteratorTemplateMacro(call); \
vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call);
class vtkStdString;
class vtkObjectBase;
class vtkAbstractArray;
class VTK_COMMON_EXPORT vtkVariant
{
public:
// Description:
// Create an invalid variant.
vtkVariant();
// Description:
// Destruct the variant.
~vtkVariant();
// Description:
// Copy constructor.
vtkVariant(const vtkVariant & other);
// Description:
// Create a string variant from a std string.
vtkVariant(vtkStdString value);
// Description:
// Create a string variant from a const char*.
vtkVariant(const char* value);
// Description:
// Create a float variant.
vtkVariant(float value);
// Description:
// Create a double variant.
vtkVariant(double value);
// Description:
// Create an integer variant.
vtkVariant(int value);
#if defined(VTK_TYPE_USE___INT64)
// Description:
// Create an __int64 variant.
vtkVariant(__int64 value);
// Description:
// Create an unsigned __int64 variant.
vtkVariant(unsigned __int64 value);
#endif
#if defined(VTK_TYPE_USE_LONG_LONG)