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 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
/*=========================================================================
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 "vtkVVDataItemVolumeContourCollection.h"
#include "vtkObjectFactory.h"
#include "vtkCollection.h"
#include "vtkSmartPointer.h"
#include "vtkVVDataItemVolume.h"
#include "vtkVVDataItemVolumeContour.h"
#include "vtkGarbageCollector.h"
//---------------------------------------------------------------------------
// Set of default colors. In so far as possible, when we add a new contour to
// a data-item, a new unique (or least used) default color is picked for you
// automagically.
double vtkVVDataItemVolumeContourCollectionDefaultColors[][3] =
{
{ 0.4, 1.0, 0.4 },
{ 1.0, 0.4, 0.4 },
{ 0.4, 0.4, 1.0 },
{ 1.0, 0.0, 0.4 },
{ 1.0, 0.4, 1.0 },
{ 0.4, 1.0, 1.0 },
{ 1.0, 0.2, 0.5 },
{ 0.3, 0.7, 0.0 },
{ 0.5, 0.2, 1.0 },
{ 1.0, 0.5, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 1.0, 0.2, 0.8 },
{ 0.2, 1.0, 0.8 },
{ 0.2, 0.4, 0.8 },
{ 0.9, 0.5, 0.2 },
{ 0.4, 0.9, 0.2 },
{ 0.5, 0.2, 0.9 },
{ 0.7, 0.3, 0.9 },
{ 0.9, 0.3, 0.5 },
{ 0.3, 0.9, 1.0 },
};
//---------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkVVDataItemVolumeContourCollection, "$Revision: 1.10 $");
vtkStandardNewMacro(vtkVVDataItemVolumeContourCollection);
//---------------------------------------------------------------------------
vtkVVDataItemVolumeContourCollection::vtkVVDataItemVolumeContourCollection()
{
this->Collection = vtkCollection::New();
this->DataItemVolume = NULL;
}
//---------------------------------------------------------------------------
vtkVVDataItemVolumeContourCollection::~vtkVVDataItemVolumeContourCollection()
{
this->SetDataItemVolume(NULL);
this->Collection->Delete();
}
//---------------------------------------------------------------------------
vtkVVDataItemVolumeContour * vtkVVDataItemVolumeContourCollection::AddNewItem()
{
vtkSmartPointer< vtkVVDataItemVolumeContour > c
= vtkSmartPointer< vtkVVDataItemVolumeContour >::New();
// Randomly pick a color
c->SetColor(vtkVVDataItemVolumeContourCollectionDefaultColors[rand() % 20]);
this->AddItem( c );
return c;
}
//---------------------------------------------------------------------------
// Add an object to the list. Prevents duplicate entries.
void vtkVVDataItemVolumeContourCollection::AddItem( vtkVVDataItemVolumeContour *a )
{
if (!this->IsItemPresent(a))
{
a->SetDataItemVolume(this->DataItemVolume);
this->Collection->AddItem(a);
}
}
//---------------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection::RemoveItem( vtkVVDataItemVolumeContour *a )
{
this->Collection->RemoveItem(a);
}
//---------------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection::RemoveAllItems()
{
this->Collection->RemoveAllItems();
}
//---------------------------------------------------------------------------
int vtkVVDataItemVolumeContourCollection::IsItemPresent( vtkVVDataItemVolumeContour *a )
{
return this->Collection->IsItemPresent(a);
}
//---------------------------------------------------------------------------
int vtkVVDataItemVolumeContourCollection::GetNumberOfItems()
{
return this->Collection->GetNumberOfItems();
}
//---------------------------------------------------------------------------
vtkVVDataItemVolumeContour *
vtkVVDataItemVolumeContourCollection::GetNthItem(int i)
{
return vtkVVDataItemVolumeContour::SafeDownCast(
this->Collection->GetItemAsObject(i) );
}
//---------------------------------------------------------------------------
// Remove the i'th item in the list.
void vtkVVDataItemVolumeContourCollection::RemoveItem(int i)
{
this->Collection->RemoveItem(i);
}
//---------------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection
::SetDataItemVolume( vtkVVDataItemVolume *v )
{
vtkSetObjectBodyMacro( DataItemVolume, vtkVVDataItemVolume, v );
// Propagate to all items on this list.
const int n = this->GetNumberOfItems();
for (int i = 0; i < n; i++)
{
this->GetNthItem(i)->SetDataItemVolume(v);
}
}
//---------------------------------------------------------------------------
int vtkVVDataItemVolumeContourCollection
::GetNumberOfContoursWithDescription( const char *description )
{
int retVal = 0;
const int n = this->GetNumberOfItems();
for (int i = 0; i < n; i++)
{
const char *contourDescription = this->GetNthItem(i)->GetDescription();
if (contourDescription == NULL && description == NULL)
{
++retVal;
}
else if (contourDescription && description)
{
std::string contourDescriptionString = contourDescription;
std::string descriptionString = description;
retVal += (contourDescriptionString.compare(descriptionString) == 0 ? 1 : 0);
}
}
return retVal;
}
//----------------------------------------------------------------------------
vtkVVDataItemVolumeContour * vtkVVDataItemVolumeContourCollection
::GetNthContourWithDescription( int k, const char *description )
{
int nthContourWithDescription = 0;
const int n = this->GetNumberOfItems();
for (int i = 0; i < n; i++)
{
vtkVVDataItemVolumeContour *contour = this->GetNthItem(i);
const char *contourDescription = contour->GetDescription();
bool isEqual = false;
if (contourDescription == NULL && description == NULL)
{
isEqual = true;
}
else if (contourDescription && description)
{
std::string contourDescriptionString = contourDescription;
std::string descriptionString = description;
isEqual = (contourDescriptionString.compare(descriptionString) == 0);
}
if (isEqual)
{
if (nthContourWithDescription == k)
{
return contour;
}
++nthContourWithDescription;
}
}
return NULL;
}
//----------------------------------------------------------------------------
// Determine the modified time of this object
unsigned long vtkVVDataItemVolumeContourCollection::GetMTime()
{
unsigned long result = 0;
// Get the max of all contours in the collection.
vtkVVDataItemVolumeContour *a;
vtkCollectionSimpleIterator ait;
for ( this->Collection->InitTraversal(ait);
(a=static_cast< vtkVVDataItemVolumeContour * >(
this->Collection->GetNextItemAsObject(ait))); )
{
unsigned long t = a->GetMTime();
if (t > result) { result = t; }
}
// Check the collection itself for changes.
unsigned long mtime = this->Collection->GetMTime();
result = ( mtime > result ? mtime : result);
// Finally check ourselves.
mtime = vtkObject::GetMTime();
result = ( mtime > result ? mtime : result);
return result;
}
//----------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection::Register( vtkObjectBase *o )
{
this->RegisterInternal(o, 1);
}
//----------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection::UnRegister( vtkObjectBase *o )
{
this->UnRegisterInternal(o, 1);
}
//----------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->DataItemVolume, "DataItemVolume");
}
//---------------------------------------------------------------------------
void vtkVVDataItemVolumeContourCollection::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|