<commit_before>/*=========================================================================

Library:   TubeTK

Copyright Kitware Inc.

All rights reserved.

Licensed under the Apache License, Version 2.0 ( the "License" );
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=========================================================================*/

#include "tubeWriteTubesAsPolyData.h"

#include "tubeMessage.h"

#include <itkGroupSpatialObject.h>
#include <itkTubeSpatialObject.h>
#include <itksys/SystemTools.hxx>

#include <vtkCellArray.h>
#include <vtkDoubleArray.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataWriter.h>
#include <vtkPolyLine.h>
#include <vtkSTLWriter.h>
#include <vtkTubeFilter.h>
#include <vtkTriangleFilter.h>
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkXMLPolyDataWriter.h>

namespace tube
{

WriteTubesAsPolyData::
WriteTubesAsPolyData()
{
  m_GroupSpatialObject = nullptr;

  m_FileName = "";
  m_CenterlineFileName = "";

  m_NumberOfSides = 5;
}

/** Main work happens here */
void WriteTubesAsPolyData::
Update()
{
  const unsigned int Dimension = 3;

  typedef itk::TubeSpatialObject< Dimension >       TubeSpatialObjectType;
  typedef itk::GroupSpatialObject< Dimension >      GroupSpatialObjectType;

  m_GroupSpatialObject->Update();

  char childName[] = "Tube";
  typedef TubeSpatialObjectType::ChildrenListType ChildrenListType;
  ChildrenListType * tubeList =
    m_GroupSpatialObject->GetChildren( m_GroupSpatialObject->GetMaximumDepth(),
      childName );

  itk::SizeValueType totalNumberOfPoints = 0;
  for( ChildrenListType::iterator tubeIt = tubeList->begin();
      tubeIt != tubeList->end();
      ++tubeIt )
    {
    TubeSpatialObjectType * tube =
      static_cast< TubeSpatialObjectType * >( tubeIt->GetPointer() );

    tube->RemoveDuplicatePointsInObjectSpace();

    const itk::SizeValueType numberOfPoints = tube->GetNumberOfPoints();
    if( numberOfPoints < 2 )
      {
      continue;
      }

    totalNumberOfPoints += numberOfPoints;
    }

  // Create the points
  vtkNew< vtkPoints > tubeSpatialPoints;
  tubeSpatialPoints->SetNumberOfPoints( totalNumberOfPoints );

  // Create the Lines
  vtkNew< vtkCellArray > tubeLines;

  // Create scalar array that indicates the radius at each
  // centerline point.
  vtkNew< vtkDoubleArray > tubeRadius;
  tubeRadius->SetName( "Radius" );
  tubeRadius->SetNumberOfTuples( totalNumberOfPoints );

  // Create scalar array that indicates TubeId.
  vtkNew< vtkDoubleArray > tubeIds;
  tubeIds->SetName( "Id" );
  tubeIds->SetNumberOfTuples( totalNumberOfPoints );

  // Create scalar array that indicates both tangents at each
  // centerline point.
  vtkNew< vtkDoubleArray > normal1;
  normal1->SetName( "Normal1" );
  normal1->SetNumberOfTuples( Dimension * totalNumberOfPoints );
  normal1->SetNumberOfComponents( Dimension );

  vtkNew< vtkDoubleArray > normal2;
  normal2->SetName( "Normal2" );
  normal2->SetNumberOfTuples( Dimension * totalNumberOfPoints );
  normal2->SetNumberOfComponents( Dimension );

  bool containsAlpha1Info = false;
  vtkNew< vtkDoubleArray > alpha1;
  alpha1->SetName( "Alpha1" );
  alpha1->SetNumberOfTuples( totalNumberOfPoints );

  bool containsAlpha2Info = false;
  vtkNew< vtkDoubleArray > alpha2;
  alpha2->SetName( "Alpha2" );
  alpha2->SetNumberOfTuples( totalNumberOfPoints );

  bool containsAlpha3Info = false;
  vtkNew< vtkDoubleArray > alpha3;
  alpha3->SetName( "Alpha3" );
  alpha3->SetNumberOfTuples( totalNumberOfPoints );

  bool containsMedialnessInfo = false;
  vtkNew< vtkDoubleArray > medialness;
  medialness->SetName( "Medialness" );
  medialness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsRidgenessInfo = false;
  vtkNew< vtkDoubleArray > ridgeness;
  ridgeness->SetName( "Ridgeness" );
  ridgeness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsBranchnessInfo = false;
  vtkNew< vtkDoubleArray > branchness;
  branchness->SetName( "Branchness" );
  branchness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsIntensityInfo = false;
  vtkNew< vtkDoubleArray > intensity;
  intensity->SetName( "Intensity" );
  intensity->SetNumberOfTuples( totalNumberOfPoints );

  bool containsCurvatureInfo = false;
  vtkNew< vtkDoubleArray > curvature;
  curvature->SetName( "Curvature" );
  curvature->SetNumberOfTuples( totalNumberOfPoints );

  bool containsRoundnessInfo = false;
  vtkNew< vtkDoubleArray > roundness;
  roundness->SetName( "Roundness" );
  roundness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsLevelnessInfo = false;
  vtkNew< vtkDoubleArray > levelness;
  levelness->SetName( "Levelness" );
  levelness->SetNumberOfTuples( totalNumberOfPoints );

  std::list<vtkDoubleArray *> extraPointData;
  TubeSpatialObjectType * tube =
    static_cast< TubeSpatialObjectType * >( tubeList->begin()->GetPointer() );
  unsigned int numExtra =
    tube->GetPoints().begin()->GetTagScalarDictionary().size();
  auto pntDictIt = tube->GetPoints().begin()->GetTagScalarDictionary().begin();
  auto pntDictItEnd = tube->GetPoints().begin()->GetTagScalarDictionary().end();
  vtkDoubleArray * extraPointField;
  while( pntDictIt != pntDictItEnd )
    {
    extraPointField = vtkDoubleArray::New();<commit_msg>COMP: Fixed compiler warnings for tubeWriteTubesAsPolyData.<commit_after>/*=========================================================================

Library:   TubeTK

Copyright Kitware Inc.

All rights reserved.

Licensed under the Apache License, Version 2.0 ( the "License" );
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=========================================================================*/

#include "tubeWriteTubesAsPolyData.h"

#include "tubeMessage.h"

#include <itkGroupSpatialObject.h>
#include <itkTubeSpatialObject.h>
#include <itksys/SystemTools.hxx>

#include <vtkCellArray.h>
#include <vtkDoubleArray.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataWriter.h>
#include <vtkPolyLine.h>
#include <vtkSTLWriter.h>
#include <vtkTubeFilter.h>
#include <vtkTriangleFilter.h>
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkXMLPolyDataWriter.h>

namespace tube
{

WriteTubesAsPolyData::
WriteTubesAsPolyData()
{
  m_GroupSpatialObject = nullptr;

  m_FileName = "";
  m_CenterlineFileName = "";

  m_NumberOfSides = 5;
}

/** Main work happens here */
void WriteTubesAsPolyData::
Update()
{
  const unsigned int Dimension = 3;

  m_GroupSpatialObject->Update();

  char childName[] = "Tube";
  typedef TubeSpatialObjectType::ChildrenListType ChildrenListType;
  ChildrenListType * tubeList =
    m_GroupSpatialObject->GetChildren( m_GroupSpatialObject->GetMaximumDepth(),
      childName );

  itk::SizeValueType totalNumberOfPoints = 0;
  for( ChildrenListType::iterator tubeIt = tubeList->begin();
      tubeIt != tubeList->end();
      ++tubeIt )
    {
    TubeSpatialObjectType * tube =
      static_cast< TubeSpatialObjectType * >( tubeIt->GetPointer() );

    tube->RemoveDuplicatePointsInObjectSpace();

    const itk::SizeValueType numberOfPoints = tube->GetNumberOfPoints();
    if( numberOfPoints < 2 )
      {
      continue;
      }

    totalNumberOfPoints += numberOfPoints;
    }

  // Create the points
  vtkNew< vtkPoints > tubeSpatialPoints;
  tubeSpatialPoints->SetNumberOfPoints( totalNumberOfPoints );

  // Create the Lines
  vtkNew< vtkCellArray > tubeLines;

  // Create scalar array that indicates the radius at each
  // centerline point.
  vtkNew< vtkDoubleArray > tubeRadius;
  tubeRadius->SetName( "Radius" );
  tubeRadius->SetNumberOfTuples( totalNumberOfPoints );

  // Create scalar array that indicates TubeId.
  vtkNew< vtkDoubleArray > tubeIds;
  tubeIds->SetName( "Id" );
  tubeIds->SetNumberOfTuples( totalNumberOfPoints );

  // Create scalar array that indicates both tangents at each
  // centerline point.
  vtkNew< vtkDoubleArray > normal1;
  normal1->SetName( "Normal1" );
  normal1->SetNumberOfTuples( Dimension * totalNumberOfPoints );
  normal1->SetNumberOfComponents( Dimension );

  vtkNew< vtkDoubleArray > normal2;
  normal2->SetName( "Normal2" );
  normal2->SetNumberOfTuples( Dimension * totalNumberOfPoints );
  normal2->SetNumberOfComponents( Dimension );

  bool containsAlpha1Info = false;
  vtkNew< vtkDoubleArray > alpha1;
  alpha1->SetName( "Alpha1" );
  alpha1->SetNumberOfTuples( totalNumberOfPoints );

  bool containsAlpha2Info = false;
  vtkNew< vtkDoubleArray > alpha2;
  alpha2->SetName( "Alpha2" );
  alpha2->SetNumberOfTuples( totalNumberOfPoints );

  bool containsAlpha3Info = false;
  vtkNew< vtkDoubleArray > alpha3;
  alpha3->SetName( "Alpha3" );
  alpha3->SetNumberOfTuples( totalNumberOfPoints );

  bool containsMedialnessInfo = false;
  vtkNew< vtkDoubleArray > medialness;
  medialness->SetName( "Medialness" );
  medialness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsRidgenessInfo = false;
  vtkNew< vtkDoubleArray > ridgeness;
  ridgeness->SetName( "Ridgeness" );
  ridgeness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsBranchnessInfo = false;
  vtkNew< vtkDoubleArray > branchness;
  branchness->SetName( "Branchness" );
  branchness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsIntensityInfo = false;
  vtkNew< vtkDoubleArray > intensity;
  intensity->SetName( "Intensity" );
  intensity->SetNumberOfTuples( totalNumberOfPoints );

  bool containsCurvatureInfo = false;
  vtkNew< vtkDoubleArray > curvature;
  curvature->SetName( "Curvature" );
  curvature->SetNumberOfTuples( totalNumberOfPoints );

  bool containsRoundnessInfo = false;
  vtkNew< vtkDoubleArray > roundness;
  roundness->SetName( "Roundness" );
  roundness->SetNumberOfTuples( totalNumberOfPoints );

  bool containsLevelnessInfo = false;
  vtkNew< vtkDoubleArray > levelness;
  levelness->SetName( "Levelness" );
  levelness->SetNumberOfTuples( totalNumberOfPoints );

  std::list<vtkDoubleArray *> extraPointData;
  TubeSpatialObjectType * tube =
    static_cast< TubeSpatialObjectType * >( tubeList->begin()->GetPointer() );
  auto pntDictIt = tube->GetPoints().begin()->GetTagScalarDictionary().begin();
  auto pntDictItEnd = tube->GetPoints().begin()->GetTagScalarDictionary().end();
  vtkDoubleArray * extraPointField;
  while( pntDictIt != pntDictItEnd )
    {
    extraPointField = vtkDoubleArray::New();
{'fraction_non_alphanumeric': 0.1287339971550498, 'fraction_numerical': 0.005867709815078236, 'mean_word_length': 5.133587786259542, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 169, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2475273', 'n_tokens_mistral': 3634, 'n_tokens_neox': 3493, 'n_words': 778}