⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extractpixeldataview.cpp

📁 DICOM专用的显示源代码,国外的一位高手写的 我贡献出来给大家学习学习
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if ( TransferSyntax >= CDcmRegistry::JPEG_Baseline_1_8 && 
		TransferSyntax <= CDcmRegistry::JPEG_2000  )
	{
		if ( TransferSyntax == CDcmRegistry::JPEG_LNHFOP_14 ) return;

		CDialog dlg;

		dlg.Create( IDD_DIALOG1 );
		dlg.CenterWindow();
		dlg.ShowWindow(SW_SHOW );

		CObList list;
		ipm.GetPixelData(list);
	
		CByteArray* frame = NULL;
		GetDocument()->m_Width = ipm.Columns();
		GetDocument()->m_Height = ipm.Rows();

		int CurrentImage = 1;
		for ( POSITION pos = list.GetHeadPosition(); pos != NULL; list.GetNext(pos ), CurrentImage++ )
		{
			frame = (CByteArray*)list.GetAt( pos );
			ASSERT ( frame != NULL );
			if ( frame == NULL ) continue;
			if ( frame->GetSize() == 0 ) continue;
		
			CString temp;
			temp.Format("Loading Encapsulated jpeg Image Fragment %d of  %d", CurrentImage, list.GetCount() );
			dlg.SetWindowText(temp);
		// Allow some time for status
			::Sleep( 2 );
			GetDocument()->m_jpegPixelData.Add(  frame  );
		}
		dlg.DestroyWindow();
	}
	else
	{
		CObList frame_list;
		switch ( TransferSyntax )
		{
			case CDcmRegistry::RLE_Lossless:
			case CDcmRegistry::ImplicitVRLittleEndian:
			case CDcmRegistry::ExplicitVRLittleEndian:
			case CDcmRegistry::ExplicitVRBigEndian:
				{
					CObList list;
					ipm.GetPixelData(list);
					// Some files can be multiframe but have the pixel data 
					// in one aggregate buffer without delimitation.
					// Create multiframe buffer if required
					if ( !mfm.NumberOfFrames().IsEmpty()  )
					{
						int frame_cnt = 0;
						::sscanf( mfm.NumberOfFrames(), "%d", &frame_cnt );
						if ( list.GetCount() == 1 && frame_cnt > 1 )
						{
							POSITION pos = list.GetHeadPosition();
							CByteArray* frame = (CByteArray*)list.GetAt( pos );
							if ( frame != NULL )
							{
								int frame_size = frame->GetSize() / frame_cnt;
								for ( int i = 0; i < frame_cnt; i++ )
								{
									CByteArray* temp = new CByteArray();	
									if ( temp != NULL )
									{
										temp->SetSize( frame_size );
										memcpy (temp->GetData(), frame->GetData()+(i*frame_size), frame_size ); 
										frame_list.AddTail( temp );
									}
								}
								list.RemoveAll();
								list.AddTail(&frame_list);
								// Convert to Multiframe 
								ipm.SetPixelData(list); 
							}
						}
					}
					// Provide some status for slow machines and big files
					CDialog dlg;
					dlg.Create( IDD_DIALOG1 );
					dlg.CenterWindow();
					dlg.ShowWindow(SW_SHOW );
					int CurrentImage = 1;
					CByteArray* frame = NULL;
					for ( POSITION pos = list.GetHeadPosition(); pos != NULL; list.GetNext(pos ),
						CurrentImage++ )
					{
						frame = (CByteArray*)list.GetAt( pos );
						ASSERT ( frame != NULL );

						if ( frame == NULL ) continue;
						if ( frame->GetSize() == 0 ) continue;
					
						unsigned short width =	GetDocument()->m_Width = ipm.Columns();
						unsigned short height = GetDocument()->m_Height = ipm.Rows();
						unsigned short BitsPerPixel = GetDocument()->m_BitsPerPixel = ipm.BitsAllocated();
						unsigned short BitsStored = ipm.BitsStored();
						
						CByteArray RleDecode;
						CByteArray *temp = NULL;
						if ( TransferSyntax == CDcmRegistry::RLE_Lossless )
						{
							CString status;
							status.Format("Loading RLE Compressed Pixel Data Fragment %d of %d", CurrentImage, list.GetCount() );
							dlg.SetWindowText(status);
							ipm.DcmRleDecode( *frame, RleDecode );
							temp = &RleDecode;
						}
						else
						{
							temp = frame;
							CString status;
							status.Format("Loading Native Pixel Data Fragment %d of %d", CurrentImage, list.GetCount() );
							dlg.SetWindowText(status);
						}
						CByteArray& ImageFragment = *temp;
						int Photometric = registry.PhotoMetricEnum( ipm.PhotoMetricInterpretation() );
						switch ( BitsPerPixel )
						{
							case 8:
							{
								if ( Photometric == CDcmRegistry::DcmPalleteColor )
								{
									BitsPerPixel = 24;
									
									CByteArray ArrayRgb;
									
									ipm.DcmColorLutDecode( ImageFragment, ArrayRgb );
								
									CByteArray* array =   new CByteArray;
									ASSERT ( array != NULL );
									if ( array != NULL )
									{
										ipm.DcmSwapRgb( ArrayRgb, height, width );
										array->Copy( ArrayRgb );
										GetDocument()->m_CookedPixelData.Add(array);
										GetDocument()->m_BitsPerPixel = 24;
									}
								}
								else if ( Photometric == CDcmRegistry::DcmRgb )
								{
									if ( ipm.PlanarConfiguration() == 1 )
									{
										int plane_size = ImageFragment.GetSize() / 3;
										CByteArray temp;
										temp.SetSize( ImageFragment.GetSize() );
										for ( int i = 0, k = 0 ; k < plane_size; i+=3, k++ )
										{
											temp[i] = ImageFragment[k];
											temp[i+1]= ImageFragment[plane_size + k];
											temp[i+2] = ImageFragment[2*plane_size + k];
										}
										ImageFragment.SetSize(0);
										ImageFragment.Copy( temp );
									}
									CByteArray* array =   new CByteArray;
									ASSERT ( array != NULL );
									if ( array != NULL )
									{
										ipm.DcmSwapRgb( ImageFragment, height, width );
										array->Copy( ImageFragment );
										GetDocument()->m_CookedPixelData.Add(array);
										GetDocument()->m_BitsPerPixel = 24;
									}
								}
								else
								{
									CByteArray* array = new CByteArray;
									ASSERT ( array != NULL );
									if ( array != NULL )
									{
										array->Copy( ImageFragment );
										GetDocument()->m_CookedPixelData.Add(array);
										GetDocument()->m_BitsPerPixel = 8;
									}
								}
							}
							break;

							case 16:
							{
								float w = 1;
								float c = 1;
								float k_1 = 0;
								float k_2 = 0;
							
								bool window = false;
								if ( vlm.WindowWidth().GetSize() && vlm.WindowCenter().GetSize() )
								{
									::sscanf( vlm.WindowWidth()[0], "%f", &w );
									::sscanf( vlm.WindowCenter()[0], "%f", &c );
									k_1 = (c - .5) - ((w-1)/2);	
									k_2 = (c - .5) + ((w-1)/2);
									window = true;
								}
								float s = 1;
								float b = 0;
								int slope = false;
							
								if ( !mlm.RescaleSlope().IsEmpty() && !mlm.Intercept().IsEmpty() )
								{
									::sscanf( mlm.RescaleSlope(), "%f", &s );
									::sscanf( mlm.Intercept(), "%f", &b );
									slope = true;
                                }
								if ( slope || window )
								{
									int largest = 0xffff;
									int smallest = 0;

									for ( int i = 0; (i+2) < ImageFragment.GetSize(); i+=2 )
									{
									   int temp = 0 ;
									   memcpy (&temp, &ImageFragment[i], 2 );
									   if ( slope )  temp =  s*temp + b;
                                  	   if ( window )
									   {
										   if ( temp <=  k_1  )
										   {
												temp = smallest;
										   }
										   else if ( temp > k_2 ) 
										   {
												temp = largest;
										   }
										   else
										   {
												temp = ((temp - (c-.5)) / (w-1) + .5) * (largest-smallest) + smallest;
										   }  
									   }
									   memcpy (&ImageFragment[i], &temp,  2 );
									}  
								}

								CByteArray Array_8;
								ipm.Dcm16BitTo8Bit( ImageFragment, Array_8 );
								CByteArray* array =   new CByteArray;
								ASSERT ( array != NULL );
								if ( array != NULL )
								{
									Array_8.SetSize( width * height );
									array->Copy( Array_8 );
									GetDocument()->m_CookedPixelData.Add(array);
									GetDocument()->m_BitsPerPixel = 8;
								}
							}
							break;
							default:
								ASSERT ( false );
							break;

						}
					}
					dlg.DestroyWindow();
					for ( pos = frame_list.GetHeadPosition(); pos != NULL; frame_list.GetNext( pos ) )
						delete frame_list.GetAt ( pos ); 
			}
			break;
		default:
			ASSERT( false );
			break;
		}
	}
}

void CExtractPixelDataView::OnNextDocument() 
{
	CMDIFrameWnd* pFrame = ((CMDIChildWnd*)GetParent())->GetMDIFrame();
	::SendMessage(pFrame->m_hWndMDIClient, WM_MDINEXT, (WPARAM)GetParent()->GetSafeHwnd() , (LPARAM) false );
	
}

void CExtractPixelDataView::OnPrevDocument() 
{
	CMDIFrameWnd* pFrame = ((CMDIChildWnd*)GetParent())->GetMDIFrame();
	 ::SendMessage(pFrame->m_hWndMDIClient, WM_MDINEXT, (WPARAM)GetParent()->GetSafeHwnd() , (LPARAM) true);
	
}

void CExtractPixelDataView::OnUpdatePrevDocument(CCmdUI* pCmdUI) 
{
	if ( AfxGetApp()->m_pDocManager->GetOpenDocumentCount() < 2 )
	{
		pCmdUI->Enable(false);
	}
	
}

void CExtractPixelDataView::OnUpdateNextDocument(CCmdUI* pCmdUI) 
{
	if ( AfxGetApp()->m_pDocManager->GetOpenDocumentCount() < 2 )
	{
		pCmdUI->Enable(false);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -