Exemple #1
0
void mitkIpPicPutSlice( const char *outfile_name, mitkIpPicDescriptor *pic, mitkIpUInt4_t slice )
{
  mitkIpPicDescriptor *pic_in;

  FILE *outfile;
  
  size_t ignored;

  pic_in = mitkIpPicGetHeader( outfile_name,
                           NULL );

  if( pic_in == NULL )
    {
      if( slice == 1 )
        {
          mitkIpBool_t compression;

          pic->n[pic->dim] = 1;
          pic->dim += 1;

          compression = mitkIpPicSetWriteCompression( mitkIpFalse );
          mitkIpPicPut( outfile_name, pic );
          mitkIpPicSetWriteCompression( compression );

          pic->dim -= 1;
          pic->n[pic->dim] = 0;

          return;
        }
      else
        return;
    }

  pic_in = mitkIpPicGetTags( outfile_name,
                         pic_in );

  outfile = fopen( outfile_name, "r+b" );

  if( outfile == NULL )
    {
      /*ipPrintErr( "mitkIpPicPut: sorry, error opening outfile\n" );*/
      /*return();*/
    }

  if( pic->dim != pic_in->dim - 1 )
    {
      fclose( outfile );
      return;
    }
  else if( pic->n[0] != pic_in->n[0]  )
    {
      fclose( outfile );
      return;
    }
  else if( pic->n[1] != pic_in->n[1]  )
    {
      fclose( outfile );
      return;
    }

  if( slice > pic_in->n[pic_in->dim-1] )
    pic_in->n[pic_in->dim-1] += 1;

  /* write outfile */
  /*fseek( outfile, 0, SEEK_SET );*/
  rewind( outfile );
  ignored = fwrite( mitkIpPicVERSION, 1, sizeof(mitkIpPicTag_t), outfile );

  fseek( outfile, sizeof(mitkIpUInt4_t), SEEK_CUR ); /* skip tags_len */

  ignored = mitkIpFWriteLE( &(pic_in->type), sizeof(mitkIpUInt4_t), 1, outfile );
  ignored = mitkIpFWriteLE( &(pic_in->bpe), sizeof(mitkIpUInt4_t), 1, outfile );
  ignored = mitkIpFWriteLE( &(pic_in->dim), sizeof(mitkIpUInt4_t), 1, outfile );

  ignored = mitkIpFWriteLE( pic_in->n, sizeof(mitkIpUInt4_t), pic_in->dim, outfile );

  fseek( outfile, pic_in->info->pixel_start_in_file + _mitkIpPicSize(pic) * (slice - 1), SEEK_SET );

  ignored = mitkIpFWriteLE( pic->data, pic->bpe / 8, _mitkIpPicElements(pic), outfile );

  /*fseek( outfile, 0, SEEK_END );*/

  fclose( outfile );

  mitkIpPicFree(pic_in);

  /*return();*/
}
Exemple #2
0
main( int argc, char *argv[] )
{
  XtAppContext app_context;
  Widget toplevel, bb, pic, annotation;
  /*Widget button;*/


  toplevel = XtVaAppInitialize( &app_context,
                                "Test",
                                NULL, 0,
                                &argc, argv,
                                fallback_resources,
                                NULL );

  XtAddEventHandler( toplevel,
                     (EventMask)0,
                     True,_XEditResCheckMessages,
                     NULL );

  n = 0;
  XtSetArg( args[n], XmNheight, 400 ); n++;
  XtSetArg( args[n], XmNwidth, 400 ); n++;

  XtSetValues( toplevel, args, n );

  bb = XmCreateDrawingArea( toplevel, "bb", args, n );
  XtManageChild( bb );


  n = 0;
  XtSetArg( args[n], XmNx, 200 ); n++;
  XtSetArg( args[n], XmNy, 100 ); n++;
  annotation = XtCreateManagedWidget( "annotation",
                                      xipAnnotationWidgetClass,
                                      bb,
                                      args, n );
  XtAddCallback( annotation, XipNactivateCallback, activate, NULL );

  n = 0;
  XtSetArg( args[n], XmNx, 0 ); n++;
  XtSetArg( args[n], XmNy, 0 ); n++;
  XtSetArg( args[n], XipNquantisation, True ); n++;
  XtSetArg( args[n], XipNpic, mitkIpPicGet( "../b.pic", NULL ) ); n++;
  pic = XtCreateManagedWidget( "pic",
                               xipPicWidgetClass,
                               bb,
                               args, n );
/**************/
  XtRealizeWidget( toplevel );
/**************/
  {
    mitkIpPicDescriptor *pic;
    _mitkIpPicTagsElement_t *head;
    mitkIpPicTSV_t *tsv;

    pic = mitkIpPicGetTags( "../b.pic",
                        NULL );
    tsv = mitkIpPicQueryTag( pic, "ANNOTATION" );
    if( tsv != NULL )
      {
        head = tsv->value;

        tsv = _mitkIpPicFindTag( head, "TEXT" )->tsv;
        text = malloc( strlen(tsv->value) );
        strcpy( text, tsv->value );
        printf( "%s\n", text );

        tsv = _mitkIpPicFindTag( head, "POSITION" )->tsv;
        x = ((mitkIpUInt4_t *)(tsv->value))[0];
        y = ((mitkIpUInt4_t *)(tsv->value))[1];
        printf( "%i %i\n", x, y );
      }

    mitkIpPicFree( pic );
  }
/**************/
  XtVaSetValues( annotation,
                 XmNx, x,
                 XmNy, y,
                 NULL );
/**************/
  XtAppMainLoop(app_context);
}
Exemple #3
0
mitkIpPicDescriptor *
MITKipPicGetTags( char *infile_name, mitkIpPicDescriptor *pic )
{
  return mitkIpPicGetTags(infile_name, pic);
}
mitk::Image::Pointer mitk::PicFileReader::CreateImage()
{
  Image::Pointer output = Image::New();

  std::string fileName = this->GetLocalFileName();

  mitkIpPicDescriptor *header = mitkIpPicGetHeader(const_cast<char *>(fileName.c_str()), NULL);

  if (!header)
  {
    mitkThrow() << "File could not be read.";
  }

  header = mitkIpPicGetTags(const_cast<char *>(fileName.c_str()), header);

  int channels = 1;

  mitkIpPicTSV_t *tsv;
  if ((tsv = mitkIpPicQueryTag(header, "SOURCE HEADER")) != NULL)
  {
    if (tsv->n[0] > 1e+06)
    {
      mitkIpPicTSV_t *tsvSH;
      tsvSH = mitkIpPicDelTag(header, "SOURCE HEADER");
      mitkIpPicFreeTag(tsvSH);
    }
  }
  if ((tsv = mitkIpPicQueryTag(header, "ICON80x80")) != NULL)
  {
    mitkIpPicTSV_t *tsvSH;
    tsvSH = mitkIpPicDelTag(header, "ICON80x80");
    mitkIpPicFreeTag(tsvSH);
  }
  if ((tsv = mitkIpPicQueryTag(header, "VELOCITY")) != NULL)
  {
    ++channels;
    mitkIpPicDelTag(header, "VELOCITY");
  }

  if (header == NULL || header->bpe == 0)
  {
    mitkThrow() << " Could not read file " << fileName;
  }

  // if pic image only 2D, the n[2] value is not initialized
  unsigned int slices = 1;
  if (header->dim == 2)
  {
    header->n[2] = slices;
  }

  // First initialize the geometry of the output image by the pic-header
  SlicedGeometry3D::Pointer slicedGeometry = mitk::SlicedGeometry3D::New();
  PicHelper::InitializeEvenlySpaced(header, header->n[2], slicedGeometry);

  // if pic image only 3D, the n[3] value is not initialized
  unsigned int timesteps = 1;
  if (header->dim > 3)
  {
    timesteps = header->n[3];
  }

  slicedGeometry->ImageGeometryOn();
  ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
  timeGeometry->Initialize(slicedGeometry, timesteps);

  // Cast the pic descriptor to ImageDescriptor and initialize the output

  output->Initialize(CastToImageDescriptor(header));
  output->SetTimeGeometry(timeGeometry);
  mitkIpPicFree(header);

  return output;
}
  bool ToFCameraMITKPlayerController::OpenCameraConnection()
  {
    if(!this->m_ConnectionCheck)
    {
      try
      {
        mitkIpPicDescriptor* pic = NULL;
        mitkIpPicDescriptor* info = NULL;

        pic = mitkIpPicGetHeader(const_cast<char *>(this->m_DistanceImageFileName.c_str()), pic);
        if (pic==NULL)
        {
          MITK_ERROR << "Error opening ToF data file " << this->m_InputFileName;
          return false;
        }
        info = mitkIpPicGetTags(const_cast<char *>(this->m_DistanceImageFileName.c_str()), pic);
        this->m_PixelStartInFile = info->info->pixel_start_in_file;

        if (pic->dim == 2)
        {
          this->m_ToFImageType = ToFImageType2DPlusT;
        }
        else if (pic->dim == 3)
        {
          this->m_ToFImageType = ToFImageType3D;
        }
        else if (pic->dim == 4)
        {
          this->m_ToFImageType = ToFImageType2DPlusT;
        }
        else
        {
          MITK_ERROR << "Error opening ToF data file: Invalid dimension.";
          return false;
        }

        this->m_CaptureWidth = pic->n[0];
        this->m_CaptureHeight = pic->n[1];
        this->m_PixelNumber = this->m_CaptureWidth*this->m_CaptureHeight;
        this->m_NumberOfBytes = this->m_PixelNumber * sizeof(float);
        if (this->m_ToFImageType == ToFImageType2DPlusT)
        {
          this->m_NumOfFrames = pic->n[3];
        }
        else
        {
          this->m_NumOfFrames = pic->n[2];
        }

        // allocate buffer
        this->m_DistanceArray = new float[this->m_PixelNumber];
        for(int i=0; i<this->m_PixelNumber; i++) {this->m_DistanceArray[i]=0.0;}
        this->m_AmplitudeArray = new float[this->m_PixelNumber]; 
        for(int i=0; i<this->m_PixelNumber; i++) {this->m_AmplitudeArray[i]=0.0;}
        this->m_IntensityArray = new float[this->m_PixelNumber];
        for(int i=0; i<this->m_PixelNumber; i++) {this->m_IntensityArray[i]=0.0;}

        OpenPicFileToData(&(this->m_DistanceInfile), this->m_DistanceImageFileName.c_str());
        OpenPicFileToData(&(this->m_AmplitudeInfile), this->m_AmplitudeImageFileName.c_str());
        OpenPicFileToData(&(this->m_IntensityInfile), this->m_IntensityImageFileName.c_str());

        MITK_INFO << "NumOfFrames: " << this->m_NumOfFrames;

        this->m_ConnectionCheck = true;
        return this->m_ConnectionCheck;
      }
      catch(std::exception& e)
      {
        MITK_ERROR << "Error opening ToF data file " << this->m_InputFileName << " " << e.what();
        throw std::logic_error("Error opening ToF data file");
        return false;
      }
    }
    else 
      return this->m_ConnectionCheck;
  }