コード例 #1
0
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());
}
コード例 #2
0
int AssignPointAttributeToCoordinatesFilter::RequestData(
    vtkInformation * /*request*/,
    vtkInformationVector ** inputVector,
    vtkInformationVector * outputVector)
{
    auto inData = vtkPointSet::SafeDownCast(inputVector[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
    auto outData = vtkPointSet::SafeDownCast(outputVector->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));

    auto previousPointCoords = inData->GetPoints()->GetData();
    vtkDataArray * pointsToAssign = nullptr;

    if (!this->AttributeArrayToAssign.empty())
    {
        auto newPoints = inData->GetPointData()->GetArray(this->AttributeArrayToAssign.c_str());
        if (!newPoints)
        {
            vtkErrorMacro("Array to assign not found in input data: " + this->AttributeArrayToAssign);
            return 0;
        }

        if (newPoints->GetNumberOfComponents() != 3
            || newPoints->GetNumberOfTuples() != inData->GetNumberOfPoints())
        {
            vtkErrorMacro("Component/Tuple count mismatching in selected data array: " + this->AttributeArrayToAssign);
            return 0;
        }
        pointsToAssign = newPoints;
    }

    outData->ShallowCopy(inData);

    if (pointsToAssign)
    {
        vtkNew<vtkPoints> newPoints;
        newPoints->SetData(pointsToAssign);
        outData->SetPoints(newPoints.Get());
    }

    // pass current point coordinates as point attribute
    if (previousPointCoords)
    {
        outData->GetPointData()->AddArray(previousPointCoords);
    }

    if (auto currentCoords = pointsToAssign ? pointsToAssign : previousPointCoords)
    {
        outData->GetPointData()->SetActiveScalars(currentCoords->GetName());
    }

    return 1;
}
コード例 #3
0
ファイル: DataArray.hpp プロジェクト: tuks188/DREAM3D
    /**
     * @brief writeXdmfAttribute
     * @param out
     * @param volDims
     * @return
     */
    virtual int writeXdmfAttribute(std::ostream &out, int64_t* volDims, const std::string &hdfFileName, const std::string &groupPath,
    const std::string &label)
    {
      if (Array == NULL) { return -85648; }
      std::stringstream dimStr;
      int precision = 0;
      std::string xdmfTypeName;
      GetXdmfTypeAndSize(xdmfTypeName, precision);
      if (0 == precision)
      {
        out << "<!-- " << GetName() << " has unkown type or unsupported type or precision for XDMF to understand" << " -->" << std::endl;
        return -100;
      }

      int numComp = GetNumberOfComponents();
      out << "    <Attribute Name=\"" << GetName() << label  << "\" ";
      if (numComp == 1)
      {
        out << "AttributeType=\"Scalar\" ";
        dimStr << volDims[2] << " " << volDims[1] << " " << volDims[0] << " ";
      }
      else
      {
        out << "AttributeType=\"Vector\" ";
        dimStr << volDims[2] << " " << volDims[1] << " " << volDims[0] << " " << numComp << " ";
      }
      out << "Center=\"Cell\">" << std::endl;
      // Open the <DataItem> Tag
      out << "      <DataItem Format=\"HDF\" Dimensions=\"" << dimStr.str() <<  "\" ";
      out << "NumberType=\"" << xdmfTypeName << "\" " << "Precision=\"" << precision << "\" >" << std::endl;


      out << "        " << hdfFileName << groupPath << "/" << GetName() << std::endl;
      out << "      </DataItem>" << std::endl;
      out << "    </Attribute>" << std::endl << std::endl;
      return 1;
    }
コード例 #4
0
ファイル: Exporter.cpp プロジェクト: kateyy/geohazardvis
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;
}
コード例 #5
0
ファイル: DataArray.hpp プロジェクト: tuks188/DREAM3D
 /**
  *
  * @param parentId
  * @return
  */
 virtual int writeH5Data(hid_t parentId)
 {
   if (Array == NULL) { return -85648; }
   return H5DataArrayWriter<T>::writeArray(parentId, GetName(), GetNumberOfTuples(), GetNumberOfComponents(), Array, getFullNameOfClass());
 }
コード例 #6
0
ファイル: components.cpp プロジェクト: hydrays/osrm-backend
int main(int argc, char *argv[])
{
    std::vector<osrm::extractor::QueryNode> coordinate_list;
    osrm::util::LogPolicy::GetInstance().Unmute();

    // enable logging
    if (argc < 2)
    {
        osrm::util::Log(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
        return EXIT_FAILURE;
    }

    std::vector<osrm::tools::TarjanEdge> graph_edge_list;
    auto number_of_nodes =
        osrm::tools::loadGraph(std::string(argv[1]), coordinate_list, graph_edge_list);

    tbb::parallel_sort(graph_edge_list.begin(), graph_edge_list.end());
    const auto graph = std::make_shared<osrm::tools::TarjanGraph>(number_of_nodes, graph_edge_list);
    graph_edge_list.clear();
    graph_edge_list.shrink_to_fit();

    osrm::util::Log() << "Starting SCC graph traversal";

    auto tarjan = std::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
    tarjan->Run();
    osrm::util::Log() << "identified: " << tarjan->GetNumberOfComponents() << " many components";
    osrm::util::Log() << "identified " << tarjan->GetSizeOneCount() << " size 1 SCCs";

    // output
    TIMER_START(SCC_RUN_SETUP);

    // remove files from previous run if exist
    osrm::tools::deleteFileIfExists("component.dbf");
    osrm::tools::deleteFileIfExists("component.shx");
    osrm::tools::deleteFileIfExists("component.shp");

    OGRRegisterAll();

    const char *psz_driver_name = "ESRI Shapefile";
    auto *po_driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(psz_driver_name);
    if (nullptr == po_driver)
    {
        throw osrm::util::exception("ESRI Shapefile driver not available" + SOURCE_REF);
    }
    auto *po_datasource = po_driver->CreateDataSource("component.shp", nullptr);

    if (nullptr == po_datasource)
    {
        throw osrm::util::exception("Creation of output file failed" + SOURCE_REF);
    }

    auto *po_srs = new OGRSpatialReference();
    po_srs->importFromEPSG(4326);

    auto *po_layer = po_datasource->CreateLayer("component", po_srs, wkbLineString, nullptr);

    if (nullptr == po_layer)
    {
        throw osrm::util::exception("Layer creation failed." + SOURCE_REF);
    }
    TIMER_STOP(SCC_RUN_SETUP);
    osrm::util::Log() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000. << "s";

    TIMER_START(SCC_OUTPUT);
    uint64_t total_network_length = 0;
    {
        osrm::util::UnbufferedLog log;
        log << "Constructing geometry ";
        osrm::util::Percent percentage(log, graph->GetNumberOfNodes());
        for (const NodeID source : osrm::util::irange(0u, graph->GetNumberOfNodes()))
        {
            percentage.PrintIncrement();
            for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
            {
                const auto target = graph->GetTarget(current_edge);

                if (source < target || SPECIAL_EDGEID == graph->FindEdge(target, source))
                {
                    total_network_length +=
                        100 * osrm::util::coordinate_calculation::greatCircleDistance(
                                  coordinate_list[source], coordinate_list[target]);

                    BOOST_ASSERT(current_edge != SPECIAL_EDGEID);
                    BOOST_ASSERT(source != SPECIAL_NODEID);
                    BOOST_ASSERT(target != SPECIAL_NODEID);

                    const unsigned size_of_containing_component =
                        std::min(tarjan->GetComponentSize(tarjan->GetComponentID(source)),
                                 tarjan->GetComponentSize(tarjan->GetComponentID(target)));

                    // edges that end on bollard nodes may actually be in two distinct components
                    if (size_of_containing_component < 1000)
                    {
                        OGRLineString line_string;
                        line_string.addPoint(static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[source].lon)),
                                             static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[source].lat)));
                        line_string.addPoint(static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[target].lon)),
                                             static_cast<double>(osrm::util::toFloating(
                                                 coordinate_list[target].lat)));

                        OGRFeature *po_feature =
                            OGRFeature::CreateFeature(po_layer->GetLayerDefn());

                        po_feature->SetGeometry(&line_string);
                        if (OGRERR_NONE != po_layer->CreateFeature(po_feature))
                        {
                            throw osrm::util::exception("Failed to create feature in shapefile." +
                                                        SOURCE_REF);
                        }
                        OGRFeature::DestroyFeature(po_feature);
                    }
                }
            }
        }
    }
    OGRSpatialReference::DestroySpatialReference(po_srs);
    OGRDataSource::DestroyDataSource(po_datasource);
    TIMER_STOP(SCC_OUTPUT);
    osrm::util::Log() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000. << "s";

    osrm::util::Log() << "total network distance: "
                      << static_cast<uint64_t>(total_network_length / 100 / 1000.) << " km";

    osrm::util::Log() << "finished component analysis";
    return EXIT_SUCCESS;
}