bool LFO::CreatePorts() { output[0] = GetOutputPort(Out); output[1] = GetOutputPort(CosOut); output[2] = GetOutputPort(InvOut); return true; }
TEST_F(ArrayChangeInformationFilter_test, vtkAssignAttribute_CorrectNumberOfComponentsPassedDownstream) { inAttr->SetNumberOfComponents(3); inAttr->SetNumberOfTuples(17); for (vtkIdType i = 0; i < inAttr->GetNumberOfValues(); ++i) { inAttr->SetValue(i, static_cast<float>(i)); } auto inImage = vtkSmartPointer<vtkImageData>::New(); inImage->GetPointData()->SetScalars(inAttr); inImage->SetExtent(0, 0, 2, 18, 3, 3); auto infoSource = vtkSmartPointer<InformationSource>::New(); infoSource->SetOutput(inImage); vtkDataObject::SetActiveAttributeInfo(infoSource->GetOutInfo(), vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS, inAttr->GetName(), inAttr->GetDataType(), inAttr->GetNumberOfComponents(), static_cast<int>(inAttr->GetNumberOfTuples())); filter->SetAttributeLocation(ArrayChangeInformationFilter::POINT_DATA); filter->SetAttributeType(vtkDataSetAttributes::SCALARS); filter->SetInputConnection(infoSource->GetOutputPort()); filter->EnableRenameOff(); filter->EnableSetUnitOff(); auto assignToVectors = vtkSmartPointer<vtkAssignAttribute>::New(); assignToVectors->SetInputConnection(filter->GetOutputPort()); assignToVectors->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA); auto reassignScalars = vtkSmartPointer<vtkAssignAttribute>::New(); reassignScalars->SetInputConnection(assignToVectors->GetOutputPort()); reassignScalars->Assign(vtkDataSetAttributes::VECTORS, vtkDataSetAttributes::SCALARS, vtkAssignAttribute::POINT_DATA); auto normalize = vtkSmartPointer<vtkImageNormalize>::New(); normalize->SetInputConnection(reassignScalars->GetOutputPort()); normalize->SetEnableSMP(false); normalize->SetNumberOfThreads(1); // before patching (VTK 7.1+) vtkAssignAttribute, this would cause segmentation faults normalize->Update(); auto outImg = normalize->GetOutput(); auto outScalars = outImg->GetPointData()->GetScalars(); ASSERT_EQ(inAttr->GetNumberOfComponents(), outScalars->GetNumberOfComponents()); ASSERT_EQ(inAttr->GetNumberOfTuples(), outScalars->GetNumberOfTuples()); }
void AudioIO::Process(UnsignedType SampleCount) { if (!m_RefCount) return; if (m_RealMode == 4) return; if (m_RealMode==2 || m_RealMode==3) { OUTPUTCLIENT::Get()->SendStereo(GetInputPort(LeftIn),GetInputPort(RightIn)); } if (m_RealMode==1 || m_RealMode==3) OUTPUTCLIENT::Get()->GetStereo(GetOutputPort(LeftOut),GetOutputPort(RightOut)); }
vtkSmartPointer<vtkAlgorithm> GlyphMagnitudeColorMapping::createFilter(AbstractVisualizedData & visualizedData, unsigned int port) { if (port != 0) { return vtkSmartPointer<vtkPassThrough>::New(); } const auto filterIt = m_filters.find(&visualizedData); // Return already created filter (in this case, visualizedData is valid for this mapping) if (filterIt != m_filters.end()) { return filterIt->second; } // Check if the mapping can be applied to the provided visualization const auto glyphMappingDataIt = m_glyphMappingData.find(static_cast<RenderedData3D *>(&visualizedData)); if (glyphMappingDataIt == m_glyphMappingData.end()) { return vtkSmartPointer<vtkPassThrough>::New(); } // Create the mapping pipeline assert(glyphMappingDataIt->second); auto & glyphMappingData = *glyphMappingDataIt->second; auto norm = vtkSmartPointer<vtkVectorNorm>::New(); norm->SetInputConnection(glyphMappingData.vectorDataOutputPort()); auto assignVectors = vtkSmartPointer<vtkAssignAttribute>::New(); assignVectors->Assign(m_vectorName.toUtf8().data(), vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA); assignVectors->SetInputConnection(norm->GetOutputPort()); auto setArrayName = vtkSmartPointer<ArrayChangeInformationFilter>::New(); setArrayName->EnableRenameOn(); setArrayName->SetArrayName(s_normScalarsName); setArrayName->SetAttributeType(vtkDataSetAttributes::SCALARS); setArrayName->SetAttributeLocation(IndexType::points); setArrayName->SetInputConnection(assignVectors->GetOutputPort()); m_filters[&visualizedData] = setArrayName; return setArrayName; }
void StackedImageDataLIC3D::SimpleExecute(vtkImageData * input, vtkImageData * output) { vtkDataArray * vectors = input->GetPointData()->GetVectors(); if (!vectors) { vtkGenericWarningMacro("StackeImageDataLIC3D::SimpleExecute: missing input vectors"); return; } initialize(); auto appendTo3D = vtkSmartPointer<vtkImageAppend>::New(); appendTo3D->SetAppendAxis(2); int inputExtent[6]; input->GetExtent(inputExtent); for (int position = inputExtent[4]; position < inputExtent[5]; ++position) { int sliceExtent[6]; input->GetExtent(sliceExtent); sliceExtent[4] = sliceExtent[5] = position; auto slice = vtkSmartPointer<vtkExtractVOI>::New(); slice->SetVOI(sliceExtent); slice->SetInputData(input); auto lic2D = vtkSmartPointer<vtkImageDataLIC2D>::New(); lic2D->SetInputConnection(0, slice->GetOutputPort()); lic2D->SetInputConnection(1, m_noiseImage->GetOutputPort()); lic2D->SetSteps(50); lic2D->GlobalWarningDisplayOff(); lic2D->SetContext(m_glContext); appendTo3D->AddInputConnection(lic2D->GetOutputPort()); } appendTo3D->Update(); output->DeepCopy(appendTo3D->GetOutput()); }
TEST_F(ArrayChangeInformationFilter_test, PassVectorInformation) { inAttr->SetNumberOfComponents(3); inAttr->SetNumberOfTuples(17); auto inImage = vtkSmartPointer<vtkImageData>::New(); inImage->GetPointData()->SetVectors(inAttr); inImage->SetExtent(0, 0, 2, 18, 3, 3); auto infoSource = vtkSmartPointer<InformationSource>::New(); infoSource->SetOutput(inImage); vtkDataObject::SetActiveAttributeInfo(infoSource->GetOutInfo(), vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::VECTORS, inAttr->GetName(), inAttr->GetDataType(), inAttr->GetNumberOfComponents(), static_cast<int>(inAttr->GetNumberOfTuples())); filter->SetAttributeLocation(ArrayChangeInformationFilter::POINT_DATA); filter->SetAttributeType(vtkDataSetAttributes::VECTORS); filter->SetInputConnection(infoSource->GetOutputPort()); filter->EnableRenameOff(); filter->EnableSetUnitOff(); auto getInfo = vtkSmartPointer<InformationSink>::New(); getInfo->SetInputConnection(filter->GetOutputPort()); getInfo->UpdateInformation(); auto outInfo = vtkDataObject::GetActiveFieldInformation(getInfo->GetInInfo(), vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::VECTORS); ASSERT_TRUE(outInfo); ASSERT_TRUE(outInfo->Has(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS())); ASSERT_EQ(inAttr->GetNumberOfComponents(), outInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS())); ASSERT_TRUE(outInfo->Has(vtkDataObject::FIELD_NUMBER_OF_TUPLES())); ASSERT_EQ(inAttr->GetNumberOfTuples(), outInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES())); ASSERT_TRUE(outInfo->Has(vtkDataObject::FIELD_NAME())); ASSERT_STREQ(inAttr->GetName(), outInfo->Get(vtkDataObject::FIELD_NAME())); ASSERT_TRUE(outInfo->Has(vtkDataObject::FIELD_ARRAY_TYPE())); ASSERT_EQ(inAttr->GetDataType(), outInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE())); }
void Counter::Process(UnsignedType SampleCount) { UnsignedType count = m_Count->Value(); bool Triggered = StateValue(m_TriggeredInd)->AsBoolean; UnsignedType Current = StateValue(m_CurrentInd)->AsUnsigned; FloatType CurrentLevel = StateValue(m_CurrentLevelInd)->AsFloat; for (UnsignedType n=0; n<SampleCount; n++) { if (GetInput(GetInputPort(In),n)>0) { if(!Triggered) { Triggered=true; Current++; } } else { if (Triggered) { Triggered=false; Current++; } } if (Current>=count) { CurrentLevel=-CurrentLevel; Current=0; } SetOutput(GetOutputPort(Out),n,CurrentLevel); } StateValue(m_TriggeredInd)->AsBoolean = Triggered; StateValue(m_CurrentInd)->AsUnsigned = Current; StateValue(m_CurrentLevelInd)->AsFloat = CurrentLevel; }
vtkSmartPointer<vtkPolyData> VoxelCarving::createVisualHull( const double isolevel) const { // create vtk visualization pipeline from voxel grid auto spoints = vtkSmartPointer<vtkStructuredPoints>::New(); auto vdim = static_cast<int>(voxel_dim_); spoints->SetDimensions(vdim, vdim, vdim); spoints->SetSpacing(params_.voxel_width, params_.voxel_height, params_.voxel_depth); spoints->SetOrigin(params_.start_x, params_.start_y, params_.start_z); auto farray = vtkSmartPointer<vtkFloatArray>::New(); auto vsize = static_cast<vtkIdType>(voxel_size_); farray->SetNumberOfValues(vsize); farray->SetArray(vox_array_.get(), vsize, 1); spoints->GetPointData()->SetScalars(farray); // create iso surface with marching cubes auto mc_source = vtkSmartPointer<vtkMarchingCubes>::New(); #if VTK_MAJOR_VERSION < 6 mc_source->SetInput(spoints); #else mc_source->SetInputData(spoints); #endif mc_source->SetNumberOfContours(1); mc_source->SetValue(0, isolevel); // calculate surface normals auto surface_normals = vtkSmartPointer<vtkPolyDataNormals>::New(); surface_normals->SetInputConnection(mc_source->GetOutputPort()); surface_normals->SetFeatureAngle(60.0); surface_normals->ComputePointNormalsOn(); surface_normals->Update(); return surface_normals->GetOutput(); }
bool Exporter::exportImageFormat(ImageDataObject & image, const QString & fileName) { QString ext = QFileInfo(fileName).suffix().toLower(); vtkSmartPointer<vtkImageWriter> writer; if (ext == "png") { writer = vtkSmartPointer<vtkPNGWriter>::New(); } else if (ext == "jpg" || ext == "jpeg") { writer = vtkSmartPointer<vtkJPEGWriter>::New(); } else if (ext == "bmp") { writer = vtkSmartPointer<vtkBMPWriter>::New(); } if (!writer) { return false; } const auto scalars = image.dataSet()->GetPointData()->GetScalars(); if (!scalars) { return false; } const auto components = scalars->GetNumberOfComponents(); if (components != 1 && components != 3 && components != 4) { return false; } if (scalars->GetDataType() == VTK_UNSIGNED_CHAR) { writer->SetInputData(image.dataSet()); } else { auto toUChar = vtkSmartPointer<ImageMapToColors>::New(); toUChar->SetInputData(image.dataSet()); auto lut = vtkSmartPointer<vtkLookupTable>::New(); lut->SetNumberOfTableValues(0xFF); lut->SetHueRange(0, 0); lut->SetSaturationRange(0, 0); lut->SetValueRange(0, 1); ValueRange<> totalRange; for (int c = 0; c < components; ++c) { ValueRange<> range; scalars->GetRange(range.data(), c); totalRange.add(range); } toUChar->SetOutputFormat( components == 3 ? VTK_RGB : (components == 4 ? VTK_RGBA : VTK_LUMINANCE)); toUChar->SetLookupTable(lut); writer->SetInputConnection(toUChar->GetOutputPort()); } writer->SetFileName(fileName.toUtf8().data()); writer->Write(); return true; }