Skip to content

Commit

Permalink
ENH: Before starting work on Voronoi neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddoria committed Jul 14, 2011
1 parent 848b4b7 commit cb4d63d
Show file tree
Hide file tree
Showing 31 changed files with 3,744 additions and 180 deletions.
59 changes: 9 additions & 50 deletions BSPNeighbors/BSPNeighbors.cpp
Expand Up @@ -7,46 +7,24 @@
#include <vtkPoints.h>
#include <vtkSmartPointer.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLPolyDataWriter.h>

int main(int argc, char *argv[])
void BSPNeighbors(vtkPoints* inputPoints, unsigned int centerPointId, vtkPoints* bspNeighbors)
{
// Verify arguments
if(argc < 3)
{
std::cerr << "Required arguments: input.vtp output.vtp" << std::endl;
return EXIT_FAILURE;
}

// Parse arguments
std::string inputFileName = argv[1];
std::string outputFileName = argv[2];

vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName( inputFileName.c_str() );
reader->Update();

// Find the 'k' nearest neighbors
unsigned int k = 8;

unsigned int centerPointId = 9;

double centerPoint[3];
reader->GetOutput()->GetPoint(centerPointId, centerPoint);
inputPoints->GetPoint(centerPointId, centerPoint);

// Create a vtkPoints of all points except the center point
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
for(vtkIdType i = 0; i < reader->GetOutput()->GetNumberOfPoints(); ++i)
for(vtkIdType i = 0; i < inputPoints->GetNumberOfPoints(); ++i)
{
if(i == centerPointId)
{
continue;
}
double p[3];
reader->GetOutput()->GetPoint(i, p);
inputPoints->GetPoint(i, p);
points->InsertNextPoint(p);
}

Expand All @@ -57,7 +35,9 @@ int main(int argc, char *argv[])

vtkSmartPointer<vtkIdList> result =
vtkSmartPointer<vtkIdList>::New();


// Find the k=8 nearest neighbors
unsigned int k = 8;
pointTree->FindClosestNPoints(k, centerPoint, result);

// Create a polydata of the result
Expand All @@ -76,6 +56,7 @@ int main(int argc, char *argv[])
vtkSmartPointer<vtkPolyData>::New();
kNearestPolydata->SetPoints(kNearestPoints);

// For demonstration only, we output the K nearest neighbors
{
vtkSmartPointer<vtkVertexGlyphFilter> vertexGlyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
Expand All @@ -98,10 +79,6 @@ int main(int argc, char *argv[])
// q_i is the ith nearest neighbor point
// p is the center point (for which the kNearest points were found)

// Create a vtkPoints of the BSPNeighbors
vtkSmartPointer<vtkPoints> bspNeighborPoints =
vtkSmartPointer<vtkPoints>::New();

for(unsigned int neighborId = 0; neighborId < k; ++neighborId) // test each kNeighbor point
{
bool valid = true;
Expand Down Expand Up @@ -132,26 +109,8 @@ int main(int argc, char *argv[])
// Keep the point if all of the tests passed
if(valid)
{
bspNeighborPoints->InsertNextPoint(neighborPoint);
bspNeighbors->InsertNextPoint(neighborPoint);
}
} // end kNeighbors loop

vtkSmartPointer<vtkPolyData> bspNeighborPolydata =
vtkSmartPointer<vtkPolyData>::New();
bspNeighborPolydata->SetPoints(bspNeighborPoints);

{
vtkSmartPointer<vtkVertexGlyphFilter> vertexGlyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
vertexGlyphFilter->SetInputConnection(bspNeighborPolydata->GetProducerPort());
vertexGlyphFilter->Update();

vtkSmartPointer<vtkXMLPolyDataWriter> writer =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetFileName("bspNeighbors.vtp");
writer->SetInputConnection(vertexGlyphFilter->GetOutputPort());
writer->Write();
}

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions BSPNeighbors/BSPNeighbors.h
@@ -0,0 +1,3 @@
#include <vtkPoints.h>

void BSPNeighbors(vtkPoints* points, unsigned int centerPointId, vtkPoints* neighbors);
7 changes: 5 additions & 2 deletions BSPNeighbors/CMakeLists.txt
Expand Up @@ -5,5 +5,8 @@ PROJECT(BSPNeighbors)
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(BSPNeighbors BSPNeighbors.cpp)
TARGET_LINK_LIBRARIES(BSPNeighbors ${ITK_LIBRARIES} ${VTK_LIBRARIES})
ADD_EXECUTABLE(BSPNeighborsExample Example.cpp BSPNeighbors.cpp)
TARGET_LINK_LIBRARIES(BSPNeighborsExample ${ITK_LIBRARIES} ${VTK_LIBRARIES})

ADD_EXECUTABLE(BSPNeighborsDemo Demo.cpp BSPNeighbors.cpp)
TARGET_LINK_LIBRARIES(BSPNeighborsDemo ${ITK_LIBRARIES} ${VTK_LIBRARIES})
55 changes: 55 additions & 0 deletions BSPNeighbors/Demo.cpp
@@ -0,0 +1,55 @@
// VTK
#include <vtkPoints.h>
#include <vtkSmartPointer.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLPolyDataWriter.h>

// Custom
#include "BSPNeighbors.h"

int main(int argc, char *argv[])
{
// Verify arguments
if(argc < 3)
{
std::cerr << "Required arguments: input.vtp output.vtp" << std::endl;
return EXIT_FAILURE;
}

// Parse arguments
std::string inputFileName = argv[1];
std::string outputFileName = argv[2];

vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName( inputFileName.c_str() );
reader->Update();

// Find the nearest neighbors of the 9th point
unsigned int centerPointId = 9;

vtkSmartPointer<vtkPoints> bspNeighborPoints =
vtkSmartPointer<vtkPoints>::New();

BSPNeighbors(reader->GetOutput()->GetPoints(), centerPointId, bspNeighborPoints);

vtkSmartPointer<vtkPolyData> bspNeighborPolydata =
vtkSmartPointer<vtkPolyData>::New();
bspNeighborPolydata->SetPoints(bspNeighborPoints);

{
vtkSmartPointer<vtkVertexGlyphFilter> vertexGlyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
vertexGlyphFilter->SetInputConnection(bspNeighborPolydata->GetProducerPort());
vertexGlyphFilter->Update();

vtkSmartPointer<vtkXMLPolyDataWriter> writer =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetFileName("bspNeighbors.vtp");
writer->SetInputConnection(vertexGlyphFilter->GetOutputPort());
writer->Write();
}

return EXIT_SUCCESS;
}
8 changes: 8 additions & 0 deletions BSPNeighbors/Example.cpp
@@ -0,0 +1,8 @@
// Custom
#include "BSPNeighbors.h"

int main(int argc, char *argv[])
{

return 0;
}
153 changes: 153 additions & 0 deletions VTKJournal/InsightArticle.cls
@@ -0,0 +1,153 @@
%
% InsightArticle.cls for the Insight Journal
%

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{InsightArticle}
[1998/02/25 Document class (Insight Article)]

%
% Change this to say a4paper instead of letterpaper if you want A4. These
% are the latex defaults.
%
\newcommand{\itk@paper}{letterpaper}
\newcommand{\itk@ptsize}{11pt}


%
% Commands for image and figure captions
%
\newcommand{\itkcaption}[2][]{\caption[{#1}]{\small \textsf{{#2}} \normalsize}}
\newcommand{\itkpiccaption}[2][]{\piccaption[{#1}]{\small \textsf{{#2}} \normalsize}}


% These set up the fonts for the documents.
%
% The "times" package makes the default font the PostScript Times
% font, which makes for smaller PostScript and a font that more people
% like.
%
\RequirePackage{times}\typeout{Using Times instead of Computer Modern.}


% Change the options here to get a different set of basic options, This
% is where to add things like "a4paper" or "10pt".
%
\LoadClass[\itk@paper,\itk@ptsize]{article}



\setcounter{secnumdepth}{1}



% Optional packages:
%
% If processing of these documents fails at your TeX installation,
% these may be commented out (independently) to make things work.
% These are both supplied with the current version of the teTeX
% distribution.
%
% The "fancyhdr" package makes nicer page footers reasonable to
% implement, and is used to put the chapter and section information in
% the footers.
%
\RequirePackage{fancyhdr}\typeout{Using fancier footers than usual.}


% Adding the package ifpdf in order to deal with the cases where
% pdflatex is used instead of latex.
\RequirePackage{ifpdf}\typeout{Using ifpdf for the template}


% Required package:
%
% This gives us all the Insight-specific markup that we really want.
% This should come last. Do not change this.
%
\RequirePackage{InsightJournal}

% support for module synopsis sections:
\newcommand{\itk@ModSynopsisFilename}{\jobname.syn}


% need to do one of these....
\newcommand{\itk@doHorizontalRule}{\rule{\textwidth}{1pt}}

% Define command to make reference to on-line Doxygen documentation
\newcommand{\doxygen}[1]{
\href{http://www.itk.org/Doxygen/html/classitk_1_1#1.html}{\code{itk::#1}}}

% Define command to make reference to on-line Doxygen documentation
\newcommand{\subdoxygen}[2]{
\href{http://www.itk.org/Doxygen/html/classitk_1_1#1_1_1#2.html}{\code{itk::#1::#2}}}

% Define command for the standard comment introducing classes with similar functionalities
\newcommand{\relatedClasses}{
\textbf{The following classes provide similar functionality:}}


% Change the title page to look a bit better, and fit in with the
% fncychap ``Bjarne'' style a bit better.
%
\renewcommand{\maketitle}{
\itk@doHorizontalRule
\ifpdf
\@ifundefined{pdfinfo}{}{{
% This \def is required to deal with multi-line authors; it
% changes \\ to ', ' (comma-space), making it pass muster for
% generating document info in the PDF file.
\def\\{, }
\pdfinfo{
/Author (\@author)
/Title (\@title)
}
}}
\else
% else nothing
\fi
\begin{flushright}
{\rm\Huge\itk@HeaderFamily \@title} \par
{\em\large\itk@HeaderFamily \itk@release} \par
\vspace{25pt}
{\Large\itk@HeaderFamily \@author} \par
\vspace{25pt}
\@date \par
\itk@authoraddress \par
\end{flushright}
\@thanks
\setcounter{footnote}{0}
\let\thanks\relax\let\maketitle\relax
\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
}


\let\itk@OldTableofcontents=\tableofcontents
\renewcommand{\tableofcontents}{
\begingroup
\parskip = 0mm
\itk@OldTableofcontents
\endgroup
\itk@doHorizontalRule
\vspace{12pt}
\itk@doing@page@targetstrue
}

% Fix the theindex environment to add an entry to the Table of
% Contents; this is much nicer than just having to jump to the end of
% the book and flip around, especially with multiple indexes.
%
\let\itk@OldTheindex=\theindex
\renewcommand{\theindex}{
\clearpage
\itk@OldTheindex
\addcontentsline{toc}{section}{\indexname}
}

\@ifundefined{fancyhf}{
\pagestyle{plain}}{
\pagestyle{normal}} % start this way; change for
\pagenumbering{arabic} % ToC & chapters
\setcounter{secnumdepth}{2}

\thispagestyle{empty}
6 changes: 6 additions & 0 deletions VTKJournal/InsightJournal.bib
@@ -0,0 +1,6 @@
@phdthesis{Pauly2003,
author = {Pauly, Mark},
booktitle = {Science},
title = {{Point Primitives for Interactive Modeling and Processing of 3D Geometry}},
year = {2003}
}

0 comments on commit cb4d63d

Please sign in to comment.