mitkIpPicDescriptor * MITKipPicGet( char *infile_name, mitkIpPicDescriptor *pic ) { if(pic != NULL) { mitkIpPicDescriptor * tmpPic; size_t sizePic, sizeTmpPic; tmpPic = mitkIpPicGet(infile_name, NULL); sizePic = _mitkIpPicSize(pic); sizeTmpPic = _mitkIpPicSize(tmpPic); if(sizePic != sizeTmpPic) { fprintf( stderr, "Critical: MITKipPicGet was given a pic with wrong size\n" ); return tmpPic; } memcpy(pic->data, tmpPic->data, sizePic); pic->info->tags_head = tmpPic->info->tags_head; tmpPic->info->tags_head = NULL; mitkIpPicFree(tmpPic); return pic; } else return mitkIpPicGet(infile_name, pic); }
void mitk::PicFileReader::FillImage(Image::Pointer output) { mitkIpPicDescriptor *outputPic = mitkIpPicNew(); outputPic = CastToIpPicDescriptor(output, nullptr, outputPic); mitkIpPicDescriptor *pic = mitkIpPicGet(const_cast<char *>(this->GetLocalFileName().c_str()), outputPic); // comes upside-down (in MITK coordinates) from PIC file ConvertHandedness(pic); mitkIpPicTSV_t *tsv; if ((tsv = mitkIpPicQueryTag(pic, "SOURCE HEADER")) != NULL) { if (tsv->n[0] > 1e+06) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag(pic, "SOURCE HEADER"); mitkIpPicFreeTag(tsvSH); } } if ((tsv = mitkIpPicQueryTag(pic, "ICON80x80")) != NULL) { mitkIpPicTSV_t *tsvSH; tsvSH = mitkIpPicDelTag(pic, "ICON80x80"); mitkIpPicFreeTag(tsvSH); } if ((tsv = mitkIpPicQueryTag(pic, "VELOCITY")) != NULL) { mitkIpPicDescriptor *header = mitkIpPicCopyHeader(pic, NULL); header->data = tsv->value; ConvertHandedness(header); output->SetChannel(header->data, 1); header->data = NULL; mitkIpPicFree(header); mitkIpPicDelTag(pic, "VELOCITY"); } // Copy the memory to avoid mismatches of malloc() and delete[]. // mitkIpPicGet will always allocate a new memory block with malloc(), // but MITK Images delete the data via delete[]. output->SetImportChannel(pic->data, 0, Image::CopyMemory); pic->data = nullptr; mitkIpPicFree(pic); }
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); }