void myGPUUnstructuredGridVolumeRayCastMapper::setMemoryForThreads (void) { setDevice (); dMemAlloc < double >(&(hLocalBuffers.intersectionLengths), numMaxGPUThreads * MaxNumberOfIntersections, &dMemUsageLocalBuffers, deviceID); switch (this->Scalars->GetDataType ()) { vtkTemplateMacro (dMemAlloc ((VTK_TT **) (&hLocalBuffers.nearIntersections), numMaxGPUThreads * MaxNumberOfIntersections * this->Scalars->GetNumberOfComponents (), &dMemUsageLocalBuffers, deviceID)); } if (this->CellScalars) { dMemAlloc < vtkIdType > (&(hLocalBuffers.intersectedCells), numMaxGPUThreads * MaxNumberOfIntersections, &dMemUsageLocalBuffers, deviceID); hLocalBuffers.farIntersections = hLocalBuffers.nearIntersections; } else { hLocalBuffers.intersectedCells = NULL; switch (this->Scalars->GetDataType ()) { vtkTemplateMacro (dMemAlloc ((VTK_TT **) (&hLocalBuffers.farIntersections), numMaxGPUThreads * MaxNumberOfIntersections * this->Scalars->GetNumberOfComponents (), &dMemUsageLocalBuffers, deviceID)); } } // For integrator myUnstructuredGridLinearRayIntegrator *integrator = (myUnstructuredGridLinearRayIntegrator *) this->RealRayIntegrator; //hLocalBuffers.numCPs = transferFunc->NumControlPoints; dMemAlloc < double >(&hLocalBuffers.segments, numMaxGPUThreads * MAX_NUM_CP * this->Scalars->GetNumberOfComponents (), &dMemUsageLocalBuffers, deviceID); dMemAlloc < dLocalVarPtrs > (&dLocalBuffers, 1, &dMemUsageLocalBuffers, deviceID); MEMCPY_H_to_D (dLocalBuffers, &hLocalBuffers, sizeof (dLocalVarPtrs) * 1); printf ("[GPU BunykRayCast] %.2f MB was allocated for local buffers.\n", dMemUsageLocalBuffers / (_1M_)); dMemUsage += dMemUsageLocalBuffers; }
//----------------------------------------------------------------------------- void ctkVTKHistogram::build() { Q_D(ctkVTKHistogram); if (d->DataArray.GetPointer() == 0) { d->MinBin = 0; d->MaxBin = 0; d->Bins->SetNumberOfTuples(0); return; } const int binCount = d->computeNumberOfBins(); d->Bins->SetNumberOfComponents(1); d->Bins->SetNumberOfTuples(binCount); if (binCount <= 0) { d->MinBin = 0; d->MaxBin = 0; return; } // What is the type of the array, discrete or reals if (static_cast<double>(binCount) != (d->Range[1] - d->Range[0] + 1)) { switch(d->DataArray->GetDataType()) { vtkTemplateMacro(populateIrregularBins<VTK_TT>(d->Bins, this)); } } else { switch(d->DataArray->GetDataType()) { vtkTemplateMacro(populateBins<VTK_TT>(d->Bins, this)); } } // update Min/Max values int* binPtr = d->Bins->GetPointer(0); int* endPtr = d->Bins->GetPointer(binCount-1); d->MinBin = *endPtr; d->MaxBin = *endPtr; for (;binPtr < endPtr; ++binPtr) { d->MinBin = qMin(*binPtr, d->MinBin); d->MaxBin = qMax(*binPtr, d->MaxBin); } emit changed(); }
//---------------------------------------------------------------------------- void fwVtkWindowLevelLookupTable::MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat) { if (this->UseMagnitude && inputIncrement > 1) { switch (inputDataType) { vtkTemplateMacro( fwVtkWindowLevelLookupTableMapMag(this,static_cast<VTK_TT*>(input),output, numberOfValues,inputIncrement,outputFormat); return ); case VTK_BIT: vtkErrorMacro("Cannot comput magnitude of bit array."); break; default: vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType"); } } switch (inputDataType) { case VTK_BIT: { vtkIdType i, id; vtkBitArray *bitArray = vtkBitArray::New(); bitArray->SetVoidArray(input,numberOfValues,1); vtkUnsignedCharArray *newInput = vtkUnsignedCharArray::New(); newInput->SetNumberOfValues(numberOfValues); for (id=i=0; i<numberOfValues; i++, id+=inputIncrement) { newInput->SetValue(i, bitArray->GetValue(id)); } fwVtkWindowLevelLookupTableMapData(this, static_cast<unsigned char*>(newInput->GetPointer(0)), output,numberOfValues, inputIncrement,outputFormat); newInput->Delete(); bitArray->Delete(); } break; vtkTemplateMacro( fwVtkWindowLevelLookupTableMapData(this,static_cast<VTK_TT*>(input),output, numberOfValues,inputIncrement,outputFormat) ); default: vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType"); return; } }
//---------------------------------------------------------------------------- // This method contains a switch statement that calls the correct // templated function for the input data type. This method does handle // boundary conditions. void vtkMitkThickSlicesFilter::ThreadedRequestData(vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector*, vtkImageData*** inData, vtkImageData** outData, int outExt[6], int threadId) { // Get the input and output data objects. vtkImageData* input = inData[0][0]; vtkImageData* output = outData[0]; // The ouptut scalar type must be double to store proper gradients. /* if(output->GetScalarType() != VTK_DOUBLE) { vtkErrorMacro("Execute: output ScalarType is " << output->GetScalarType() << "but must be double."); return; } */ vtkDataArray* inputArray = this->GetInputArrayToProcess(0, inputVector); if (!inputArray) { vtkErrorMacro("No input array was found. Cannot execute"); return; } // Gradient makes sense only with one input component. This is not // a Jacobian filter. if(inputArray->GetNumberOfComponents() != 1) { vtkErrorMacro( "Execute: input has more than one component. " "The input to gradient should be a single component image. " "Think about it. If you insist on using a color image then " "run it though RGBToHSV then ExtractComponents to get the V " "components. That's probably what you want anyhow."); return; } void* inPtr = inputArray->GetVoidPointer(0); void* outPtr = output->GetScalarPointerForExtent(outExt); switch(inputArray->GetDataType()) { vtkTemplateMacro( vtkMitkThickSlicesFilterExecute(this, input, static_cast<VTK_TT*>(inPtr), output, static_cast<VTK_TT*>(outPtr), outExt, threadId) ); default: vtkErrorMacro("Execute: Unknown ScalarType " << input->GetScalarType()); return; } }
// Method to run the filter in different threads. void vtkMitkLevelWindowFilter::ThreadedExecute(vtkImageData *inData, vtkImageData *outData, int extent[6], int /*id*/) { if (inData->GetNumberOfScalarComponents() > 2) { switch (inData->GetScalarType()) { vtkTemplateMacro( vtkApplyLookupTableOnRGBA(this, inData, outData, extent, m_ClippingBounds, static_cast<VTK_TT *>(nullptr))); default: vtkErrorMacro(<< "Execute: Unknown ScalarType"); return; } } else {
//---------------------------------------------------------------------------- // This method contains a switch statement that calls the correct // templated function for the input data type. This method does handle // boundary conditions. void LofarIntegrateFrequencies::ThreadedRequestData(vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector*, vtkImageData*** inData, vtkImageData** outData, int outExt[6], int threadId) { // Get the input and output data objects. vtkImageData* input = inData[0][0]; vtkImageData* output = outData[0]; // The ouptut scalar type must be double to store proper gradients. if(output->GetScalarType() != VTK_DOUBLE) { vtkErrorMacro("Execute: output ScalarType is " << output->GetScalarType() << "but must be double."); return; } vtkDataArray* inputArray = this->GetInputArrayToProcess(0, inputVector); if (!inputArray) { vtkErrorMacro("No input array was found. Cannot execute"); return; } // Integration only works on scalars. if(inputArray->GetNumberOfComponents() != 1) { vtkErrorMacro("Execute: input has more than one component. "); return; } void* inPtr = inputArray->GetVoidPointer(0); double* outPtr = static_cast<double *>( output->GetScalarPointerForExtent(outExt)); switch(inputArray->GetDataType()) { vtkTemplateMacro( LofarIntegrateFrequenciesExecute(this, input, static_cast<VTK_TT*>(inPtr), output, outPtr, outExt, threadId) ); default: vtkErrorMacro("Execute: Unknown ScalarType " << input->GetScalarType()); return; } }
//---------------------------------------------------------------------------- // This method convolves over one axis. It loops over the convolved axis, // and handles boundary conditions. void SeparableBilateralFilter::ExecuteAxis(int axis, vtkImageData *inData, int inExt[6], vtkImageData *outData, int outExt[6], int *pcycle, int target, int *pcount, int total, vtkInformation *inInfo) { int idxA, max; int wholeExtent[6], wholeMax, wholeMin; double *kernel; // previousClip and currentClip rembers that the previous was not clipped // keeps from recomputing kernels for center pixels. int kernelLeftClip, kernelRightClip; int previousClipped, currentClipped; int kernelSizeClipped = 0; void *inPtr; void *outPtr; int coords[3]; vtkIdType *outIncs, outIncA; // Get the correct starting pointer of the output outPtr = outData->GetScalarPointerForExtent(outExt); outIncs = outData->GetIncrements(); outIncA = outIncs[axis]; // trick to account for the scalar type of the output(used to be only float) switch (outData->GetScalarType()) { vtkTemplateMacro( outIncA *= SeparableBilateralFilterGetTypeSize(static_cast<VTK_TT*>(0)) ); default: vtkErrorMacro("Unknown scalar type"); return; } // Determine default starting position of input coords[0] = inExt[0]; coords[1] = inExt[2]; coords[2] = inExt[4]; // get whole extent for boundary checking ... inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent); wholeMin = wholeExtent[axis * 2]; wholeMax = wholeExtent[axis * 2 + 1]; // allocate memory for the kernel kernel = new double[KernelSize]; int radius = int(KernelSize / 2.0); // loop over the convolution axis previousClipped = currentClipped = 1; max = outExt[axis * 2 + 1]; for (idxA = outExt[axis * 2]; idxA <= max; ++idxA) { // left boundary condition coords[axis] = idxA - radius; kernelLeftClip = wholeMin - coords[axis]; if (kernelLeftClip > 0) { // front of kernel is cut off ("kernelStart" samples) coords[axis] += kernelLeftClip; } else { kernelLeftClip = 0; } // Right boundary condition kernelRightClip = (idxA + radius) - wholeMax; if (kernelRightClip < 0) { kernelRightClip = 0; } // We can only use previous kernel if it is not clipped and new // kernel is also not clipped. currentClipped = kernelLeftClip + kernelRightClip; if (currentClipped || previousClipped) { this->ComputeKernel(kernel, -radius + kernelLeftClip, radius - kernelRightClip); kernelSizeClipped = KernelSize - kernelLeftClip - kernelRightClip; } previousClipped = currentClipped; /* now do the convolution on the rest of the axes */ inPtr = inData->GetScalarPointer(coords); switch (inData->GetScalarType()) { vtkTemplateMacro( SeparableBilateralFilterExecute(this, axis, kernel, kernelSizeClipped, inData, static_cast<VTK_TT*>(inPtr), outData, outExt, static_cast<VTK_TT*>(outPtr), pcycle, target, pcount, total) ); default: vtkErrorMacro("Unknown scalar type"); return; } outPtr = static_cast<void *>( static_cast<unsigned char *>(outPtr)+outIncA); } // get rid of temporary kernel delete[] kernel; }
vtkDataArray * avtMagnitudeExpression::DeriveVariable(vtkDataSet *in_ds, int currentDomainsIndex) { // // The base class will set the variable of interest to be the // 'activeVariable'. This is a by-product of how the base class sets its // input. If that method should change (SetActiveVariable), this // technique for inferring the variable name may stop working. // const char *varname = activeVariable; vtkDataArray *vectorValues = in_ds->GetPointData()->GetArray(varname); if (vectorValues == NULL) { vectorValues = in_ds->GetCellData()->GetArray(varname); } if (vectorValues == NULL) { EXCEPTION2(ExpressionException, outputVariableName, "Unable to locate variable for magnitude expression"); } if (vectorValues->GetNumberOfComponents() != 3) { EXCEPTION2(ExpressionException, outputVariableName, "Can only take magnitude of vectors."); } vtkIdType ntuples = vectorValues->GetNumberOfTuples(); vtkDataArray *results = vectorValues->NewInstance(); results->SetNumberOfComponents(1); results->SetNumberOfTuples(ntuples); #define COMPUTE_MAG(dtype) \ { \ dtype *x = (dtype*)vectorValues->GetVoidPointer(0); \ dtype *r = (dtype*)results->GetVoidPointer(0); \ for (vtkIdType i = 0, idx = 0 ; i < ntuples ; i++, idx += 3) \ { \ r[i] = sqrt((double)x[idx+0]*(double)x[idx+0]+\ (double)x[idx+1]*(double)x[idx+1]+\ (double)x[idx+2]*(double)x[idx+2]); \ } \ } if(vectorValues->HasStandardMemoryLayout()) { switch(vectorValues->GetDataType()) { vtkTemplateMacro(COMPUTE_MAG(VTK_TT)); } } else { for(vtkIdType i = 0; i < ntuples ; i++) { const double *x = vectorValues->GetTuple(i); results->SetTuple1(i, sqrt(x[0]*x[0]+ x[1]*x[1]+ x[2]*x[2])); } } return results; }