📄 extractpixeldatadoc.cpp
字号:
{
CFile f( pathname, CFile::modeWrite|CFile::modeCreate );
CArchive ar( &f, CArchive::store );
for( int i = 0; i < Attributes.GetSize(); i++ )
{
ar.WriteString( Attributes[i] );
ar.WriteString( "\n" );
}
HINSTANCE code = ::ShellExecute( ::GetDesktopWindow() , "open", pathname,
NULL, NULL, SW_MAXIMIZE);
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "CreateDcmExportFile->File could not be opened " << e->m_cause << "\n";
#endif
}
END_CATCH
}
void CExtractPixelDataDoc::OnUpdateButtonBack(CCmdUI* pCmdUI)
{
if ( m_CookedPixelData.GetSize() + m_jpegPixelData.GetSize() <= 1 )
{
pCmdUI->Enable( false );
}
}
void CExtractPixelDataDoc::OnUpdateButtonForward(CCmdUI* pCmdUI)
{
if ( m_CookedPixelData.GetSize() + m_jpegPixelData.GetSize() <= 1 )
{
pCmdUI->Enable( false );
}
}
bool CExtractPixelDataDoc::IsSelected( int index )
{
bool sel = false;
for( int i = 0; i < m_SelectedImages.GetSize(); i++ )
{
if ( index == m_SelectedImages[i] )
{
sel = true;
break;
}
}
return sel;
}
void CExtractPixelDataDoc::AddSelection( int index )
{
if ( m_jpegPixelData.GetSize() != 0 )
{
if ( index < m_jpegPixelData.GetSize() )
{
if ( !IsSelected( index ) )
{
m_SelectedImages.Add( index );
}
}
}
else if ( m_CookedPixelData.GetSize() != 0 )
{
if ( index < m_CookedPixelData.GetSize() )
{
if ( !IsSelected( index ) )
{
m_SelectedImages.Add( index );
}
}
}
}
void CExtractPixelDataDoc::RemoveSelection( int index )
{
for( int i = 0; i < m_SelectedImages.GetSize(); i++ )
{
if ( index == m_SelectedImages[i] )
{
m_SelectedImages.RemoveAt(i);
break;
}
}
}
void CExtractPixelDataDoc::OnChooseImage()
{
if ( IsSelected( m_ImageIndex ) )
{
RemoveSelection( m_ImageIndex );
}
else
{
AddSelection( m_ImageIndex );
}
SetIndexedTitle(m_ImageIndex);
}
void CExtractPixelDataDoc::OnUpdateChooseImage(CCmdUI* pCmdUI)
{
}
void CExtractPixelDataDoc::OnCreateSelDataset()
{
CFileDialog dlg (false, "dic", "dataset", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT );
CString pathname;
if ( dlg.DoModal() == IDOK )
{
pathname = dlg.m_ofn.lpstrFile;
CDcmCompositeIOD iod;
TRY
{
CDcmImagePixelModule ipm;
CDcmMetaFileInformation mfi;
CDcmMultiFrameModule mfm;
CFile f( pathname, CFile::modeWrite|CFile::modeCreate );
CArchive ar( &f, CArchive::store );
if ( m_CookedPixelData.GetSize() != 0 )
{
ipm = m_ImagePixel;
CObList list;
ipm.GetPixelData(list);
CObList SelectedList;
int FrameCount = 0;
for ( int i = 0; i < m_SelectedImages.GetSize(); i++ )
{
POSITION pos = list.FindIndex( m_SelectedImages[i] );
if ( pos != NULL )
{
CByteArray* frame = (CByteArray*)list.GetAt( pos );
ASSERT ( frame != NULL );
if ( frame != NULL )
{
FrameCount++;
SelectedList.AddTail( frame );
}
}
}
ipm.SetPixelData(SelectedList);
mfm = m_MultiFrame, mfi = m_MetaFile;
mfm.NumberOfFrames().Format("%d", FrameCount );
mfi.SourceApplicationEntity() = "Dicom Scribble V1.01";
iod << mfi << mfm << ipm << m_VioLut << m_ModalityLut;
}
else if ( m_jpegPixelData.GetSize() != 0 )
{
ipm = m_ImagePixel;
CObList list;
ipm.SetPixelData(list);
int FrameCount = 0;
for ( int i = 0; i < m_SelectedImages.GetSize(); i++ )
{
ASSERT( m_SelectedImages[i] < m_jpegPixelData.GetSize() );
ASSERT( m_jpegPixelData[ m_SelectedImages[i] ] != NULL );
if ( m_SelectedImages[i] < m_jpegPixelData.GetSize() )
{
CByteArray* frame = ( CByteArray* )m_jpegPixelData[ m_SelectedImages[i] ];
if ( frame != NULL )
{
FrameCount++;
ipm.SetPixelData( *frame );
}
}
}
mfm = m_MultiFrame, mfi = m_MetaFile;
mfm.NumberOfFrames().Format("%d", FrameCount );
mfi.SourceApplicationEntity() = "Dicom Scribble V1.01";
iod << mfi << mfm << ipm << m_VioLut << m_ModalityLut;
}
iod.Serialize( ar );
}
CATCH( CFileException, e )
{
CString DcmError;
DcmError.Format("Could not open " + pathname );
AfxMessageBox(DcmError);
#ifdef _DEBUG
afxDump << "CreateDcmExportFile->File could not be opened " << e->m_cause << "\n";
#endif
return;
}
END_CATCH
AfxGetApp()->OpenDocumentFile( pathname );
}
}
void CExtractPixelDataDoc::OnUpdateCreateSelDataset(CCmdUI* pCmdUI)
{
if ( m_SelectedImages.GetSize() == 0 ) pCmdUI->Enable( false );
}
void CExtractPixelDataDoc::OnEmptyChoose()
{
if ( AfxMessageBox("Clear All Selections?", MB_YESNO|MB_ICONQUESTION) == IDYES )
{
m_SelectedImages.RemoveAll();
SetIndexedTitle(m_ImageIndex);
}
}
void CExtractPixelDataDoc::OnUpdateEmptyChoose(CCmdUI* pCmdUI)
{
if ( m_SelectedImages.GetSize() == 0 ) pCmdUI->Enable( false );
}
void CExtractPixelDataDoc::OnAttributeAnon55()
{
m_anonymize_55 = AfxGetApp()->GetProfileInt("DICOM Scribble", "m_anonymize_55", 0 );
if ( m_anonymize_55 )
{
m_anonymize_55 = 0;
}
else
{
m_anonymize_55 = 1;
}
AfxGetApp()->WriteProfileInt("DICOM Scribble", "m_anonymize_55", m_anonymize_55 );
}
void CExtractPixelDataDoc::OnUpdateAttributeAnon55(CCmdUI* pCmdUI)
{
if ( m_anonymize_55 )
{
pCmdUI->SetCheck();
}
else
{
pCmdUI->SetCheck(0);
}
}
void CExtractPixelDataDoc::OnImportSelection()
{
CFileDialog dlg (true, "txt", "*.txt", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT );
CUIntArray SelectArray;
CString pathname;
if ( dlg.DoModal() == IDOK )
{
TRY
{
pathname = dlg.m_ofn.lpstrFile;
CFile f( pathname, CFile::modeRead );
CArchive ar( &f, CArchive::load );
CString line;
while ( ar.ReadString( line ) )
{
line.TrimLeft();
line.TrimRight();
if ( line == "\n" ) continue; // skip empty lines
if ( line.Left( 1 ) == ";" ) continue; // allow comments
CString number;
int temp;
while ( !line.IsEmpty() )
{
number = line.SpanExcluding( "," );
line = line.Right( ( line.GetLength() - number.GetLength() ) - 1 );
number.TrimLeft(); number.TrimRight();
temp = 0;
if ( ::sscanf( number, "%d", &temp ) != 0 )
{
if ( temp < 0 ) temp = -temp;
SelectArray.Add( temp );
}
}
}
}
CATCH( CFileException, e )
{
CString DcmError;
DcmError.Format("Could not open import file " + pathname );
AfxMessageBox(DcmError);
}
END_CATCH
if ( SelectArray.GetSize() != 0 )
{
m_SelectedImages.RemoveAll();
for( int i = 0; i < SelectArray.GetSize(); i++ )
{
AddSelection( SelectArray[i] );
}
SetIndexedTitle(m_ImageIndex);
}
}
}
void CExtractPixelDataDoc::OnUpdateImportSelection(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CExtractPixelDataDoc::OnExportSel()
{
CFileDialog dlg (false, "txt", "sel", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT );
CString pathname;
if ( dlg.DoModal() == IDOK )
{
pathname = dlg.m_ofn.lpstrFile;
TRY
{
CFile f( pathname, CFile::modeWrite|CFile::modeCreate );
CArchive ar( &f, CArchive::store );
for ( int i = 0; i < m_SelectedImages.GetSize(); i++ )
{
CString temp;
temp.Format("%d", m_SelectedImages[i] );
ar.WriteString( temp );
ar.WriteString( "\n" );
}
}
CATCH( CFileException, e )
{
CString DcmError;
DcmError.Format("Could not create export file " + pathname );
AfxMessageBox(DcmError);
}
END_CATCH
}
}
void CExtractPixelDataDoc::OnUpdateExportSel(CCmdUI* pCmdUI)
{
if ( m_SelectedImages.GetSize() == 0 ) pCmdUI->Enable( false );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -