|
|
(2 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | This example produces a vtkGraph as output.
| + | = '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/GraphAlgorithmSource GraphAlgorithmSource] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' = |
− | | |
− | ==GraphAlgorithmSource.cxx==
| |
− | <source lang="cpp">
| |
− | #include <vtkSmartPointer.h>
| |
− | #include <vtkGraph.h>
| |
− | #include <vtkMutableUndirectedGraph.h>
| |
− | | |
− | #include "vtkTestGraphAlgorithmSource.h"
| |
− | | |
− | int main (int, char *[])
| |
− | {
| |
− | vtkSmartPointer<vtkTestGraphAlgorithmSource> source =
| |
− | vtkSmartPointer<vtkTestGraphAlgorithmSource>::New();
| |
− | source->Update();
| |
− |
| |
− | vtkGraph* outputGraph = source->GetOutput();
| |
− |
| |
− | std::cout << "Output number of vertices: "
| |
− | << outputGraph->GetNumberOfVertices() << std::endl;
| |
− |
| |
− | return EXIT_SUCCESS;
| |
− | }
| |
− | </source>
| |
− | | |
− | ==vtkTestGraphAlgorithmSource.h==
| |
− | <source lang="cpp">
| |
− | | |
− | #ifndef __vtkTestGraphAlgorithmSource_h
| |
− | #define __vtkTestGraphAlgorithmSource_h
| |
− | | |
− | #include "vtkGraphAlgorithm.h"
| |
− | | |
− | class vtkTestGraphAlgorithmSource : public vtkGraphAlgorithm
| |
− | {
| |
− | public:
| |
− | vtkTypeRevisionMacro(vtkTestGraphAlgorithmSource,vtkGraphAlgorithm);
| |
− | void PrintSelf(ostream& os, vtkIndent indent);
| |
− | | |
− | static vtkTestGraphAlgorithmSource *New();
| |
− |
| |
− | protected:
| |
− | vtkTestGraphAlgorithmSource();
| |
− | ~vtkTestGraphAlgorithmSource();
| |
− |
| |
− | int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
| |
− |
| |
− | int RequestDataObject(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
| |
− | | |
− | private:
| |
− | vtkTestGraphAlgorithmSource(const vtkTestGraphAlgorithmSource&); // Not implemented.
| |
− | void operator=(const vtkTestGraphAlgorithmSource&); // Not implemented.
| |
− | | |
− | };
| |
− | | |
− | #endif
| |
− | | |
− | </source>
| |
− | | |
− | ==vtkTestGraphAlgorithmSource.cxx==
| |
− | <source lang="cpp">
| |
− | #include "vtkTestGraphAlgorithmSource.h"
| |
− | | |
− | #include "vtkObjectFactory.h"
| |
− | #include "vtkStreamingDemandDrivenPipeline.h"
| |
− | #include "vtkInformationVector.h"
| |
− | #include "vtkInformation.h"
| |
− | #include "vtkDataObject.h"
| |
− | #include "vtkSmartPointer.h"
| |
− | #include "vtkMutableUndirectedGraph.h"
| |
− | #include "vtkUndirectedGraph.h"
| |
− | #include "vtkGraph.h"
| |
− | | |
− | vtkCxxRevisionMacro(vtkTestGraphAlgorithmSource, "$Revision: 1.70 $");
| |
− | vtkStandardNewMacro(vtkTestGraphAlgorithmSource);
| |
− | | |
− | vtkTestGraphAlgorithmSource::vtkTestGraphAlgorithmSource()
| |
− | {
| |
− | this->SetNumberOfInputPorts(0);
| |
− | this->SetNumberOfOutputPorts(1);
| |
− | }
| |
− | | |
− | vtkTestGraphAlgorithmSource::~vtkTestGraphAlgorithmSource()
| |
− | {
| |
− | | |
− | }
| |
− | | |
− | int vtkTestGraphAlgorithmSource::RequestData(
| |
− | vtkInformation *vtkNotUsed(request),
| |
− | vtkInformationVector **vtkNotUsed(inputVector),
| |
− | vtkInformationVector *outputVector)
| |
− | {
| |
− |
| |
− | vtkInformation *outInfo = outputVector->GetInformationObject(0);
| |
− |
| |
− | vtkGraph *output = vtkGraph::SafeDownCast(
| |
− | outInfo->Get(vtkDataObject::DATA_OBJECT()));
| |
− |
| |
− | vtkSmartPointer<vtkMutableUndirectedGraph> NewGraph =
| |
− | vtkSmartPointer<vtkMutableUndirectedGraph>::New();
| |
− |
| |
− | //add 3 vertices
| |
− | NewGraph->AddVertex();
| |
− | NewGraph->AddVertex();
| |
− | NewGraph->AddVertex();
| |
− |
| |
− | output->ShallowCopy(NewGraph);
| |
− |
| |
− | return 1;
| |
− | }
| |
− | | |
− | int vtkTestGraphAlgorithmSource::RequestDataObject(
| |
− | vtkInformation*,
| |
− | vtkInformationVector**,
| |
− | vtkInformationVector* )
| |
− | {
| |
− | | |
− | vtkUndirectedGraph *output = 0;
| |
− | output = vtkUndirectedGraph::New();
| |
− |
| |
− |
| |
− | this->GetExecutive()->SetOutputData(0, output);
| |
− | output->Delete();
| |
− | | |
− | return 1;
| |
− | }
| |
− | | |
− | //---------------------------------------------------------------------------- | |
− | void vtkTestGraphAlgorithmSource::PrintSelf(ostream& os, vtkIndent indent)
| |
− | {
| |
− | this->Superclass::PrintSelf(os,indent);
| |
− | }
| |
− | </source>
| |
− | | |
− | {{VTKCMakeListsMultiple|{{SUBPAGENAME}}|vtkTestGraphAlgorithmSource}}
| |