[vtkusers] Strange error using vtkDICOMImageReader with MFC

Łukasz Tutaj ltutaj at wp.pl
Thu Sep 29 10:06:04 EDT 2005


Hi vtk Users.

    I found strange error using vtkDICOMImageReader in my program. I use 
MDI architecture to provide GUI. I use vtkMDI example as a pattern. I've 
changed only few things, because I want to display DICOM files. The 
source code is attached below. Building process works fine and without 
any warnings but trying to display DICOM file I got error (unhalted 
exception at msvcr71d.dll: Acces violation writing location). Debugging 
the program I found that the problem is in memcpy.asm in line 171. I 
suspect that the problem is with vtkDICOMImageReader because I tried in 
this program to change only the reader class (the type of files from 
DICOM to BMP) from vtkDICOMImageReader to vtkBMPReader and my software 
works fine with BMP files. I don't know what is wrong. Is it bug in 
vtkDICOMImageReader class or something else. I use VC ++ 7 and I also 
use GUI support (vtkMFC class).



// MyMDIAppView.cpp : implementation of the CMyMDIAppView class
//

#include "stdafx.h"
#include "MyMDIApp.h"

#include "MyMDIAppDoc.h"
#include "MyMDIAppView.h"
#include ".\mymdiappview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMyMDIAppView

IMPLEMENT_DYNCREATE(CMyMDIAppView, CView)

BEGIN_MESSAGE_MAP(CMyMDIAppView, CView)
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
    ON_WM_DESTROY()
    ON_WM_CREATE()
END_MESSAGE_MAP()

// CMyMDIAppView construction/destruction

CMyMDIAppView::CMyMDIAppView()
{
    // TODO: add construction code here
    this->pvtkMFCWindow = NULL;

    this->pvtkRenderer = vtkRenderer::New();
    this->pvtkImageMapper = vtkImageMapper::New();
    this->pvtkActor2D = vtkActor2D::New();
}

CMyMDIAppView::~CMyMDIAppView()
{
    if (this->pvtkMFCWindow) delete this->pvtkMFCWindow;
}

BOOL CMyMDIAppView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    return CView::PreCreateWindow(cs);
}

// CMyMDIAppView drawing

void CMyMDIAppView::OnDraw(CDC* /*pDC*/)
{
    CMyMDIAppDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    // TODO: add draw code for native data here
}


// CMyMDIAppView printing

BOOL CMyMDIAppView::OnPreparePrinting(CPrintInfo* pInfo)
{
    // default preparation
    return DoPreparePrinting(pInfo);
}

void CMyMDIAppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add extra initialization before printing
}

void CMyMDIAppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}


// CMyMDIAppView diagnostics

#ifdef _DEBUG
void CMyMDIAppView::AssertValid() const
{
    CView::AssertValid();
}

void CMyMDIAppView::Dump(CDumpContext& dc) const
{
    CView::Dump(dc);
}

CMyMDIAppDoc* CMyMDIAppView::GetDocument() const // non-debug version is 
inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyMDIAppDoc)));
    return (CMyMDIAppDoc*)m_pDocument;
}
#endif //_DEBUG


// CMyMDIAppView message handlers

void CMyMDIAppView::ExecutePipeline()
{
  CMyMDIAppDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  if (!pDoc)
    return;

    if (pDoc->m_bHasAFile)  // have file
  {
    
//this->pvtkImageMapper->SetInput(this->GetDocument()->pvtkDICOMImageReader->GetOutput());   
   // HERE I CHANGE READER FROM vtkDICOMImageReader
    
this->pvtkImageMapper->SetInput(this->GetDocument()->pvtkBMPReader->GetOutput());   
                   // TO vtkBMPReader !!!!!!
    this->pvtkActor2D->SetMapper(this->pvtkImageMapper);
    this->pvtkRenderer->SetBackground(0.0,0.0,0.0);
    this->pvtkRenderer->AddActor(this->pvtkActor2D);
    }
}

void CMyMDIAppView::OnInitialUpdate()
{
    CView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class
     this->pvtkMFCWindow = new vtkMFCWindow(this);

  this->pvtkMFCWindow->GetRenderWindow()->AddRenderer(this->pvtkRenderer);

  // execute object pipeline
  ExecutePipeline();
}

void CMyMDIAppView::OnDestroy()
{
    CView::OnDestroy();

    // TODO: Add your message handler code here

  if (this->pvtkRenderer)     this->pvtkRenderer->Delete();
  if (this->pvtkImageMapper)  this->pvtkImageMapper->Delete();
  if (this->pvtkActor2D)      this->pvtkActor2D->Delete();
}

int CMyMDIAppView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here

    return 0;
}





More information about the vtkusers mailing list