Hej ;)
Jestem w trakcie pisania wrappera do C# ....
Mam problem gdyz program dziala mi na moim kompie .. gdzie mam wszystkie biblioteki z C++ itd..
W C# odpala sie wszystko ok;)
Natomiast problem przychodzi kiedy uruchamiam go na innej maszynie ;/
Build przechodzi ok - natomiast visual wywala mi bland przy kompilacji
**Nie można załadować biblioteki DLL 'LandmarkIGSTK.dll': Nie można odnaleźć określonego modułu. (Wyjątek od HRESULT: 0x8007007E)
**
Jesli to możliwe bardzo prosilabym o jakas pomoc, good advice ?
Mecze sie juz z tym pare miesiecy ...;/
Kod z c++ do utworzenia dll - ki :
#if defined(_MSC_VER)
//Warning about: identifier was truncated to '255' characters in the
//debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif
// BeginLatex
//
// This example illustrates how to use IGSTK's landmark registration
// component to determine rigid body transformation parameters between
// an image and the patient coordinate system.
//
// EndLatex
#include <iostream>
// BeginLatex
//
// To use the registration component, the header file for
// \doxygen{Landmark3DRegistration} is added:
//
// EndLatex
// BeginCodeSnippet
#include "igstkLandmark3DRegistration.h"
// EndCodeSnippet
#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"
#include "itkObject.h"
#include "itkCommand.h"
#include "itkMacro.h"
// BeginLatex
//
// Transform parameters are returned to the application using loaded events.
// To handle these events, the following \doxygen{Events}
// and \doxygen{Transform} header files are needed:
//
// EndLatex
// BeginCodeSnippet
#include "igstkEvents.h"
#include "igstkTransform.h"
#include "igstkCoordinateSystemTransformToResult.h"
// EndCodeSnippet
// BeginLatex
//
// To fully utilize the registration component, callbacks need to be set up
// to observe events that could be thrown by the registration component.
// For this purpose, the ITK command class is used to derive a callback class.
// The ITK command class implements a subject/observer (command design) pattern.
// A subject notifies an observer by running the \code{Execute } method of
// the derived callback class. For example, a callback class meant
// to observe an error in the transform computation is defined as follows:
//
// EndLatex
// BeginCodeSnippet
class Landmark3DRegistrationErrorCallback : public itk::Command
{
public:
typedef Landmark3DRegistrationErrorCallback Self;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::Command Superclass;
itkNewMacro(Self);
void Execute(const itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event))
{
}
void Execute(itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event))
{
std::cerr<<"Error in transform computation"<<std::endl;
}
protected:
Landmark3DRegistrationErrorCallback() {};
private:
};
//EndCodeSnippet
class Landmark3DRegistrationInvalidRequestCallback : public itk::Command
{
public:
typedef Landmark3DRegistrationInvalidRequestCallback Self;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::Command Superclass;
itkNewMacro(Self);
void Execute(const itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event) )
{
}
void Execute(itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event) )
{
std::cerr<<"Invalid input request!!"<<std::endl;
}
protected:
Landmark3DRegistrationInvalidRequestCallback() {};
private:
};
// BeginLatex
//
// Similarly, a callback class needs to be defined to observe the
// \doxygen{CoordinateSystemTransformToEvent} event. This event is loaded with
// transform parameters that are computed by the registration component. The
// commands are as follows:
// EndLatex
// BeginCodeSnippet
class Landmark3DRegistrationGetTransformCallback: public itk::Command
{
public:
typedef Landmark3DRegistrationGetTransformCallback Self;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::Command Superclass;
itkNewMacro(Self);
typedef igstk::CoordinateSystemTransformToEvent TransformEventType;
void Execute( const itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event) )
{
}
void Execute( itk::Object * itkNotUsed(caller), const itk::EventObject & event )
{
std::cout<< " TransformEvent is thrown" << std::endl;
const TransformEventType * transformEvent =
dynamic_cast < const TransformEventType* > ( &event );
const igstk::CoordinateSystemTransformToResult transformCarrier =
transformEvent->Get();
m_Transform = transformCarrier.GetTransform();
m_EventReceived = true;
}
bool GetEventReceived()
{
return m_EventReceived;
}
igstk::Transform GetTransform()
{
return m_Transform;
}
protected:
Landmark3DRegistrationGetTransformCallback()
{
m_EventReceived = true;
}
private:
bool m_EventReceived;
igstk::Transform m_Transform;
};
// EndCodeSnippet
// BeginLatex
//
// For more information on IGSTK events, see Chapter~\ref{Chapter:Events}.
// After the helper classes are defined, the main function implementation
// is started, as follows:
//
// EndLatex
extern "C"
{
__declspec(dllexport) void __stdcall Rejestracja( double tab[30], double* pReturn)
{
// EndCodeSnippet
igstk::RealTimeClock::Initialize();
// BeginLatex
//
// Next, all the necessary data types are defined:
//
// EndLatex
// BeginCodeSnippet
typedef igstk::Object::LoggerType LoggerType;
typedef itk::StdStreamLogOutput LogOutputType;
typedef igstk::Landmark3DRegistration
Landmark3DRegistrationType;
typedef igstk::Landmark3DRegistration::LandmarkPointContainerType
LandmarkPointContainerType;
typedef igstk::Landmark3DRegistration::LandmarkImagePointType
LandmarkImagePointType;
typedef igstk::Landmark3DRegistration::LandmarkTrackerPointType
LandmarkTrackerPointType;
typedef Landmark3DRegistrationType::TransformType::OutputVectorType
OutputVectorType;
typedef igstk::Transform TransformType;
// EndCodeSnippet
// BeginLatex
//
// Then, the registration component is instantiated as follows:
//
// EndLatex
// BeginCodeSnippet
Landmark3DRegistrationType::Pointer landmarkRegister =
Landmark3DRegistrationType::New();
// EndCodeSnippet
// BeginLatex
//
// Next, the landmark containers that hold the landmark image and tracker
// coordinates are instantiated:
//
// EndLatex
// BeginCodeSnippet
LandmarkPointContainerType imagePointContainer;
LandmarkPointContainerType trackerPointContainer;
// EndCodeSnippet
LandmarkImagePointType imagePoint;
LandmarkTrackerPointType trackerPoint;
// BeginLatex
//
// Then, error event callback objects are instantiated and added to the observer
// list of the registration component, as follows:
//
// EndLatex
// BeginCodeSnippet
Landmark3DRegistrationInvalidRequestCallback::Pointer
lrcb = Landmark3DRegistrationInvalidRequestCallback::New();
typedef igstk::InvalidRequestErrorEvent InvalidRequestEvent;
landmarkRegister->AddObserver( InvalidRequestEvent(), lrcb );
Landmark3DRegistrationErrorCallback::Pointer ecb =
Landmark3DRegistrationErrorCallback::New();
typedef igstk::Landmark3DRegistration::TransformComputationFailureEvent
ComputationFailureEvent;
landmarkRegister->AddObserver( ComputationFailureEvent(), ecb );
// EndCodeSnippet
// BeginLatex
//
// A logger can then be connected to the registration component for
// debugging purpose, as follows:
//
// EndLatex
// BeginCodeSnippet
LoggerType::Pointer logger = LoggerType::New();
LogOutputType::Pointer logOutput = LogOutputType::New();
logOutput->SetStream( std::cout );
logger->AddLogOutput( logOutput );
logger->SetPriorityLevel( LoggerType::DEBUG );
landmarkRegister->SetLogger( logger );
// EndCodeSnippet
// BeginLatex
//
// Next, landmark points are added to the image and tracker containers. The
// state machine of this registration component is designed so that the image
// and tracker coordinates that correspond to each landmark are added
// consecutively. This scheme prevents the mismatch in landmark correspondence
// that could occur when all landmarks image coordinates are recorded first and
// followed by the tracker coordinates. This design choice is consistent with
// the ``safety by design'' philosophy of IGSTK. The commands are as follows:
//
//EndLatex
// BeginCodeSnippet
// Add 1st landmark
imagePoint[0] = tab[0];
imagePoint[1] = tab[1];
imagePoint[2] = tab[2];
imagePointContainer.push_back(imagePoint);
landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);
trackerPoint[0] = tab[3];
trackerPoint[1] = tab[4];
trackerPoint[2] = tab[5];
trackerPointContainer.push_back(trackerPoint);
landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);
// Add 2nd landmark
imagePoint[0] = tab[6];
imagePoint[1] = tab[7];
imagePoint[2] = tab[8];
imagePointContainer.push_back(imagePoint);
landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);
trackerPoint[0] = tab[9];
trackerPoint[1] = tab[10];
trackerPoint[2] = tab[11];
trackerPointContainer.push_back(trackerPoint);
landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);
// Add 3d landmark
imagePoint[0] = tab[12];
imagePoint[1] = tab[13];
imagePoint[2] = tab[14];
imagePointContainer.push_back(imagePoint);
landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);
trackerPoint[0] = tab[15];
trackerPoint[1] = tab[16];
trackerPoint[2] = tab[17];
trackerPointContainer.push_back(trackerPoint);
landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);
// EndCodeSnippet
// BeginLatex
//
// More landmarks can be added for the transform computation.
//
// EndLatex
// Add 4th landmark
imagePoint[0] = tab[18];
imagePoint[1] = tab[19];
imagePoint[2] = tab[20];
imagePointContainer.push_back(imagePoint);
landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);
trackerPoint[0] = tab[21];
trackerPoint[1] = tab[22];
trackerPoint[2] = tab[23];
trackerPointContainer.push_back(trackerPoint);
landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);
// Add 5th landmark
imagePoint[0] = tab[24];
imagePoint[1] = tab[25];
imagePoint[2] = tab[26];
imagePointContainer.push_back(imagePoint);
landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);
trackerPoint[0] = tab[27];
trackerPoint[1] = tab[28];
trackerPoint[2] = tab[29];
trackerPointContainer.push_back(trackerPoint);
landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);
// BeginLatex
//
// After all landmark coordinates are added, the transform computation is
// requested as follows:
//
// EndLatex
// Calculate transform
// BeginCodeSnippet
landmarkRegister->RequestComputeTransform();
// EndCodeSnippet
typedef itk::VersorRigid3DTransform<double> VersorRigid3DTransformType;
typedef VersorRigid3DTransformType::ParametersType ParametersType;
TransformType transform;
ParametersType parameters(6);
// BeginLatex
//
// To access the transform parameters, a GetTransform callback is instantiated
// to observe the transform event, as follows:
//
// EndLatex
// BeginCodeSnippet
Landmark3DRegistrationGetTransformCallback::Pointer lrtcb =
Landmark3DRegistrationGetTransformCallback::New();
landmarkRegister->AddObserver(
igstk::CoordinateSystemTransformToEvent(), lrtcb );
//EndCodeSnippet
// BeginLatex
//
// To request that the registration component throw an event loaded with
// transform parameters, a \code{RequestGetTransform} function is invoked as
// follows:
//
// EndLatex
// BeginCodeSnippet
landmarkRegister->RequestGetTransformFromTrackerToImage();
transform = lrtcb->GetTransform();
std::cout << "Transform " << transform << std::cout;
// EndCodeSnippet
if(lrtcb->GetEventReceived())
{
transform = lrtcb->GetTransform();
vtkMatrix4x4 * t = vtkMatrix4x4::New();;
transform.ExportTransform( * t );
for ( int i = 0; i < 3; i++ )
{
for ( int j = 0; j < 3; j++ )
{
pReturn[4*i+j] = t->GetElement(i,j);
}
}
t->Delete();
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////
//c# - UnsafeNativeMethods.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace WrapperLandmark
{
internal static class UnsafeNativeMethods
{
const string dllLocation = "LandmarkIGSTK.dll";
[DllImport(dllLocation)]
public static extern void Rejestracja(double[] dane,IntPtr pReturn);
}
}
////////////////////////////////////////////////////////////////////////////////////////////
// c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WrapperLandmark
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Run();
}
public static void Run()
{
double[] dane = new double[30];
#region Dane
dane[0] = 25.0;
dane[1] = 1.0;
dane[2] = 15.0;
dane[3] = 29.8;
dane[4] = -5.3;
dane[5] = 25.0;
dane[6] = 15.0;
dane[7] = 21.0;
dane[8] = 17.0;
dane[9] = 35.0;
dane[10] = 16.5;
dane[11] = 27.0;
dane[12] = 14.0;
dane[13] = 25.0;
dane[14] = 11.0;
dane[15] = 36.8;
dane[16] = 20.0;
dane[17] = 21.0;
dane[18] = 10.0;
dane[19] = 11.0;
dane[20] = 8.0;
dane[21] = 24.7;
dane[22] = 12.0;
dane[23] = 18.0;
dane[24] = 26.0;
dane[25] = 2.0;
dane[26] = 16.0;
dane[27] = 30.5;
dane[28] = -6.6;
dane[29] = 26.0;
#endregion Dane
// UnsafeNativeMethods.Rejestracja(dane);
double[] wynik = new double[16];
IntPtr pWynik = Marshal.AllocHGlobal(16 * 8);
UnsafeNativeMethods.Rejestracja(dane, pWynik);
Marshal.Copy(pWynik, wynik, 0, 16);
string wynikShow = string.Empty;
for (int i = 0; i < 16; i++)
{
wynikShow = wynikShow + i.ToString() + " " + wynik[i].ToString() + "\n";
}
MessageBox.Show(wynikShow);
Marshal.FreeHGlobal(pWynik);
}
}
}