Example #1
0
void
  mitk::SlicedGeometry3D::InitializeSlicedGeometry( unsigned int slices )
{
  Superclass::Initialize();
  m_Slices = slices;

  PlaneGeometry::Pointer gnull = nullptr;
  m_PlaneGeometries.assign( m_Slices, gnull );

  Vector3D spacing;
  spacing.Fill( 1.0 );
  this->SetSpacing( spacing );

  m_DirectionVector.Fill( 0 );
}
Example #2
0
bool mitk::PicHelper::GetSpacing(const mitkIpPicDescriptor* aPic, Vector3D & spacing)
{
    mitkIpPicDescriptor* pic = const_cast<mitkIpPicDescriptor*>(aPic);

    mitkIpPicTSV_t *tsv;
    bool pixelSize = false;

    tsv = mitkIpPicQueryTag( pic, "REAL PIXEL SIZE" );
    if(tsv==NULL)
    {
        tsv = mitkIpPicQueryTag( pic, "PIXEL SIZE" );
        pixelSize = true;
    }
    if(tsv)
    {
        bool tagFound = false;
        if((tsv->dim*tsv->n[0]>=3) && (tsv->type==mitkIpPicFloat))
        {
            if(tsv->bpe==32)
            {
                FillVector3D(spacing,((mitkIpFloat4_t*)tsv->value)[0], ((mitkIpFloat4_t*)tsv->value)[1],((mitkIpFloat4_t*)tsv->value)[2]);
                tagFound = true;
            }
            else if(tsv->bpe==64)
            {
                FillVector3D(spacing,((mitkIpFloat8_t*)tsv->value)[0], ((mitkIpFloat8_t*)tsv->value)[1],((mitkIpFloat8_t*)tsv->value)[2]);
                tagFound = true;
            }
        }
        if(tagFound && pixelSize)
        {
            tsv = mitkIpPicQueryTag( pic, "PIXEL SPACING" );
            if(tsv)
            {
                mitk::ScalarType zSpacing = 0;
                if((tsv->dim*tsv->n[0]>=3) && (tsv->type==mitkIpPicFloat))
                {
                    if(tsv->bpe==32)
                    {
                        zSpacing = ((mitkIpFloat4_t*)tsv->value)[2];
                    }
                    else if(tsv->bpe==64)
                    {
                        zSpacing = ((mitkIpFloat8_t*)tsv->value)[2];
                    }
                    if(zSpacing != 0)
                    {
                        spacing[2] = zSpacing;
                    }
                }
            }
        }
        if(tagFound) return true;
    }
#ifdef HAVE_IPDICOM
    tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" );
    if( tsv )
    {
        void *data;
        mitkIpUInt4_t len;
        mitkIpFloat8_t spacing_z = 0;
        mitkIpFloat8_t thickness = 1;
        mitkIpFloat8_t fx = 1;
        mitkIpFloat8_t fy = 1;
        bool ok=false;

        if( dicomFindElement( (unsigned char *) tsv->value, 0x0018, 0x0088, &data, &len ) )
        {
            ok=true;
            sscanf( (char *) data, "%lf", &spacing_z );
//        itkGenericOutputMacro( "spacing:  " << spacing_z << " mm");
        }
        if( dicomFindElement( (unsigned char *) tsv->value, 0x0018, 0x0050, &data, &len ) )
        {
            ok=true;
            sscanf( (char *) data, "%lf", &thickness );
//        itkGenericOutputMacro( "thickness: " << thickness << " mm");

            if( thickness == 0 )
                thickness = 1;
        }
        if( dicomFindElement( (unsigned char *) tsv->value, 0x0028, 0x0030, &data, &len )
                && len>0 && ((char *)data)[0] )
        {
            sscanf( (char *) data, "%lf\\%lf", &fy, &fx );    // row / column value
//        itkGenericOutputMacro( "fx, fy: " << fx << "/" << fy  << " mm");
        }
        else
            ok=false;
        if(ok)
            FillVector3D(spacing, fx, fy,( spacing_z > 0 ? spacing_z : thickness));
        return ok;
    }
#endif /* HAVE_IPDICOM */
    if(spacing[0]<=0 || spacing[1]<=0 || spacing[2]<=0)
    {
        itkGenericOutputMacro(<< "illegal spacing by pic tag: " << spacing << ". Setting spacing to (1,1,1).");
        spacing.Fill(1);
    }
void
mitk::NormalDirectionConsistencySorter
::Sort()
{
  DICOMDatasetList datasets = GetInput();

  if (datasets.size() > 1)
  {
    // at some point in the code, there is the expectation that
    // the direction of the slice normals is the same as the direction between
    // first and last slice origin. We need to make this sure here, because
    // we want to feed the files into itk::ImageSeriesReader with the consistent
    // setting of ReverseOrderOff.

    static const DICOMTag tagImagePositionPatient = DICOMTag(0x0020,0x0032); // Image Position (Patient)
    static const DICOMTag    tagImageOrientation = DICOMTag(0x0020, 0x0037); // Image Orientation

    DICOMDatasetAccess* firstDS = datasets.front();
    DICOMDatasetAccess*  lastDS = datasets.back();

    // make sure here that the direction from slice to slice is the direction of
    // image normals...
    std::string imageOrientationString = firstDS->GetTagValueAsString( tagImageOrientation );
    std::string imagePositionPatientFirst = firstDS->GetTagValueAsString( tagImagePositionPatient );
    std::string imagePositionPatientLast = lastDS->GetTagValueAsString( tagImagePositionPatient );

    Vector3D right; right.Fill(0.0);
    Vector3D up; up.Fill(0.0);
    bool hasOrientation(false);
    DICOMStringToOrientationVectors( imageOrientationString,
        right, up, hasOrientation );

    Point3D firstOrigin; firstOrigin.Fill(0.0f);
    bool firstHasOrigin(false);
    firstOrigin = DICOMStringToPoint3D( imagePositionPatientFirst, firstHasOrigin );

    Point3D lastOrigin; lastOrigin.Fill(0.0f);
    bool lastHasOrigin(false);
    lastOrigin = DICOMStringToPoint3D( imagePositionPatientLast, lastHasOrigin );

    Vector3D normal;
    normal[0] = right[1] * up[2] - right[2] * up[1];
    normal[1] = right[2] * up[0] - right[0] * up[2];
    normal[2] = right[0] * up[1] - right[1] * up[0];
    normal.Normalize();

    Vector3D directionOfSlices;
    directionOfSlices = lastOrigin - firstOrigin;
    directionOfSlices.Normalize();

    double projection = normal * directionOfSlices;

    MITK_DEBUG << "Making sense of \norientation '" << imageOrientationString
               << "'\nfirst position '" << imagePositionPatientFirst
               << "'\nlast position '" << imagePositionPatientLast << "'";
    MITK_DEBUG << "Normal: " << normal;
    MITK_DEBUG << "Direction of slices: " << directionOfSlices;
    MITK_DEBUG << "Projection of direction onto slice normal: " << projection;

    if ( projection < 0.0 )
    {
      MITK_DEBUG << "Need to reverse filenames";
      std::reverse( datasets.begin(), datasets.end() );

      m_TiltInfo = GantryTiltInformation::MakeFromTagValues(
          imagePositionPatientLast,
          imagePositionPatientFirst,
          imageOrientationString,
          datasets.size() - 1
          );
    }
    else
    {
      m_TiltInfo = GantryTiltInformation::MakeFromTagValues(
          imagePositionPatientFirst,
          imagePositionPatientLast,
          imageOrientationString,
          datasets.size() - 1
          );
    }
  }
  else // just ONE dataset, do not forget to reset tilt information
  {
    m_TiltInfo = GantryTiltInformation(); // empty info
  }

  this->SetNumberOfOutputs(1);
  this->SetOutput(0, datasets);
}