You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
3.9 KiB
159 lines
3.9 KiB
2 years ago
|
/*=========================================================================
|
||
|
|
||
|
Program: Visualization Toolkit
|
||
|
Module: $RCSfile: vtkCompositer.cxx,v $
|
||
|
|
||
|
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 "vtkCompositer.h"
|
||
|
#include "vtkObjectFactory.h"
|
||
|
#include "vtkToolkits.h"
|
||
|
#include "vtkDataArray.h"
|
||
|
#include "vtkFloatArray.h"
|
||
|
#include "vtkUnsignedCharArray.h"
|
||
|
#include "vtkMultiProcessController.h"
|
||
|
|
||
|
#ifdef VTK_USE_MPI
|
||
|
#include <mpi.h>
|
||
|
#endif
|
||
|
|
||
|
vtkCxxRevisionMacro(vtkCompositer, "$Revision: 1.9 $");
|
||
|
vtkStandardNewMacro(vtkCompositer);
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
vtkCompositer::vtkCompositer()
|
||
|
{
|
||
|
this->Controller = vtkMultiProcessController::GetGlobalController();
|
||
|
this->NumberOfProcesses = 1;
|
||
|
if (this->Controller)
|
||
|
{
|
||
|
this->Controller->Register(this);
|
||
|
this->NumberOfProcesses = this->Controller->GetNumberOfProcesses();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
vtkCompositer::~vtkCompositer()
|
||
|
{
|
||
|
this->SetController(NULL);
|
||
|
}
|
||
|
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
void vtkCompositer::SetController(vtkMultiProcessController *mpc)
|
||
|
{
|
||
|
if (this->Controller == mpc)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
if (mpc)
|
||
|
{
|
||
|
mpc->Register(this);
|
||
|
this->NumberOfProcesses = mpc->GetNumberOfProcesses();
|
||
|
}
|
||
|
if (this->Controller)
|
||
|
{
|
||
|
this->Controller->UnRegister(this);
|
||
|
}
|
||
|
this->Controller = mpc;
|
||
|
}
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
void vtkCompositer::CompositeBuffer(vtkDataArray *pBuf, vtkFloatArray *zBuf,
|
||
|
vtkDataArray *pTmp, vtkFloatArray *zTmp)
|
||
|
{
|
||
|
pBuf = pBuf;
|
||
|
zBuf = zBuf;
|
||
|
pTmp = pTmp;
|
||
|
zTmp = zTmp;
|
||
|
}
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
|
||
|
void vtkCompositer::ResizeFloatArray(vtkFloatArray* fa, int numComp,
|
||
|
vtkIdType size)
|
||
|
{
|
||
|
fa->SetNumberOfComponents(numComp);
|
||
|
|
||
|
#ifdef MPIPROALLOC
|
||
|
vtkIdType fa_size = fa->GetSize();
|
||
|
if ( fa_size < size*numComp )
|
||
|
{
|
||
|
float* ptr = fa->GetPointer(0);
|
||
|
if (ptr)
|
||
|
{
|
||
|
MPI_Free_mem(ptr);
|
||
|
}
|
||
|
char* tptr;
|
||
|
MPI_Alloc_mem(size*numComp*sizeof(float), NULL, &tptr);
|
||
|
ptr = (float*)tptr;
|
||
|
fa->SetArray(ptr, size*numComp, 1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
fa->SetNumberOfTuples(size);
|
||
|
}
|
||
|
#else
|
||
|
fa->SetNumberOfTuples(size);
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void vtkCompositer::ResizeUnsignedCharArray(vtkUnsignedCharArray* uca,
|
||
|
int numComp, vtkIdType size)
|
||
|
{
|
||
|
uca->SetNumberOfComponents(numComp);
|
||
|
#ifdef MPIPROALLOC
|
||
|
vtkIdType uca_size = uca->GetSize();
|
||
|
|
||
|
if ( uca_size < size*numComp )
|
||
|
{
|
||
|
unsigned char* ptr = uca->GetPointer(0);
|
||
|
if (ptr)
|
||
|
{
|
||
|
MPI_Free_mem(ptr);
|
||
|
}
|
||
|
char* tptr;
|
||
|
MPI_Alloc_mem(size*numComp*sizeof(unsigned char), NULL, &tptr);
|
||
|
ptr = (unsigned char*)tptr;
|
||
|
uca->SetArray(ptr, size*numComp, 1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
uca->SetNumberOfTuples(size);
|
||
|
}
|
||
|
#else
|
||
|
uca->SetNumberOfTuples(size);
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void vtkCompositer::DeleteArray(vtkDataArray* da)
|
||
|
{
|
||
|
#ifdef MPIPROALLOC
|
||
|
void* ptr = da->GetVoidPointer(0);
|
||
|
if (ptr)
|
||
|
{
|
||
|
MPI_Free_mem(ptr);
|
||
|
}
|
||
|
#endif
|
||
|
da->Delete();
|
||
|
}
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
void vtkCompositer::PrintSelf(ostream& os, vtkIndent indent)
|
||
|
{
|
||
|
this->Superclass::PrintSelf(os, indent);
|
||
|
os << indent << "Controller: (" << this->Controller << ")\n";
|
||
|
os << indent << "NumberOfProcesses: " << this->NumberOfProcesses << endl;
|
||
|
}
|
||
|
|
||
|
|
||
|
|