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

📄 rsimagestardoc.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		tempptr->dib=new CRSImageJPEG;
	    bSuccess = tempptr->dib->Read(lpszPathName);
	}
	else if(!ext.CompareNoCase(".TIF"))
	{
		tempptr->dib=new CRSImageTIFF;
	    bSuccess = tempptr->dib->Read(lpszPathName);
	}
	else if(!ext.CompareNoCase(".BMP"))
	{
		tempptr->dib=new CRSImageBMP;
	    bSuccess = tempptr->dib->Read(lpszPathName);
	}
	else
	{
		COpenBinDlg dlg;
        if(dlg.DoModal()==IDOK)
		{
			tempptr->dib=new CRSImage;
			CRSImageBIN dib;
			dib.width=dlg.m_width;
			dib.height=dlg.m_height;
            dib.RedChannel=dlg.m_nRed;
			dib.GreenChannel=dlg.m_nGreen;
			dib.BlueChannel =dlg.m_nBlue;
			dib.m_nheadsize=dlg.m_nCount;
			dib.nByte=dlg.m_radio+1;
	        bSuccess = dib.Read(lpszPathName);
		    if(bSuccess)
			   tempptr->dib->SetDataPtr(&dib);
			else
				return ;
		}
		else
			return ;
	}
	if(tempptr->dib==NULL)
		return ;
    if (!bSuccess)
	{
		ReportSaveLoadException(lpszPathName, NULL,	FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
		return ;
	}
	if(head==NULL)
	{
		tempptr->next=NULL;
		tempptr->pre=NULL;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;
		strcpy(tempptr->layername,"图层");
 	    strcat(tempptr->layername,lpszPathName);
		head=tempptr;
		curptr=tempptr;
	}
	else
	{
		tempptr->next=NULL;
		tempptr->pre=curptr;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;
		strcpy(tempptr->layername,"图层");
 	    strcat(tempptr->layername,lpszPathName);
        curptr->flagwrite=false;        
		curptr->next=tempptr;
		curptr=tempptr;
	}

	ncount++;
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
	pMain->m_wndMyDialogBar.AddItem();

	m_Dib->SetDataPtr((CRSImage *)curptr->dib);
    m_Dib->m_hDIB=curptr->dib->m_hDIB;
    UpdateAllViews(NULL);
}

//以当前激活的图象为背景,创建新的图层
void CRSImageStarDoc::OnLayerAdd() 
{
	// TODO: Add your command handler code here
    RGBTRIPLE color;

	CString str;
	str.Format("%s%d",filename,ncount);
	CString name;
	CLayerProDlg dlg;
	dlg.m_StrName=str;
    if(dlg.DoModal()==IDOK)
    {
		color=dlg.m_Color;
		CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
		ASSERT_KINDOF(CMainFrame, pAppFrame);
		pAppFrame->m_wndPaintParamBar.ShowPenColor(dlg.LayerColor);
		pAppFrame->m_wndMyDialogBar.SetButtonColor(dlg.LayerColor);
		name=dlg.m_StrName;
	}
	else
		return;
	struct Layer *tempptr;
	tempptr=(struct Layer *)malloc(sizeof(struct Layer));
    tempptr->dib=NULL;
	BeginWaitCursor();
	tempptr->dib=new CRSImage;
	if(tempptr->dib==NULL)
		return;
    tempptr->dib->CreateLayer(name,size,color);

	if(head==NULL)
	{
		tempptr->next=NULL;
		tempptr->pre=NULL;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;
        tempptr->color.rgbtRed=255;
        tempptr->color.rgbtGreen=255;
        tempptr->color.rgbtBlue=255;
		strcpy(tempptr->layername,"背 景");

		head=tempptr;
		curptr=tempptr;
	}
	else
	{
		tempptr->next=NULL;
		tempptr->pre=curptr;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;
        tempptr->color=color;
		strcpy(tempptr->layername,"图 层");
		char num[2];
		sprintf(num,"%d",ncount);
		strcat(tempptr->layername,num);
        curptr->flagwrite=false;        
		curptr->next=tempptr;
		curptr=tempptr;
	}
	ncount++;
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
	pMain->m_wndMyDialogBar.AddItem();
	m_Dib->SetDataPtr((CRSImage *)curptr->dib);
    m_Dib->m_hDIB=curptr->dib->m_hDIB;
 //   UpdateAllViews(NULL);
}

void CRSImageStarDoc::OnLayerDelete() 
{
	// TODO: Add your command handler code here
	tempptr=curptr;
	if(curptr->pre!=NULL)
		curptr->pre->next=curptr->next;
	else
	{
	    AfxMessageBox("不能删除背景层!");	
		return;
	}
	if(curptr->next!=NULL)
	{
		curptr->next->pre=curptr->pre;
		curptr->next->flagwrite=TRUE;
        curptr=curptr->next;		
	}
	else
	{
		curptr->pre->flagwrite=TRUE;
        curptr=curptr->pre;		
	}
	m_Dib->SetDataPtr((CRSImage *)curptr->dib);
	m_Dib->m_hDIB=curptr->dib->m_hDIB;

    delete tempptr->dib;
    free(tempptr);
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
    pMain->m_wndMyDialogBar.OpenItem();

    UpdateAllViews(NULL);    
}

//进行图象通道的分离
void CRSImageStarDoc::OnChannelsplit() 
{
	// TODO: Add your command handler code here
  CRSImageStarApp* pApp =(CRSImageStarApp*)AfxGetApp();
  CRSImage red;
  CRSImage green;
  CRSImage blue;
  POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
  CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posTemplate);
  CWaitCursor wait;

  if (m_Dib->SplitChannels(red, green, blue))
  {
	CRSImageStarDoc* pDocument = (CRSImageStarDoc*) pDocTemplate->OpenDocumentFile(NULL);
    pDocument->m_Dib->SetDataPtr(&red);
    pDocument->size=size;
	if(pDocument->head==NULL)
	{
	    CString str;
		int count;
		count=filename.GetLength();
		str=filename.Left(count-4);
		CString ext;
		ext.Format("%s","(Red).bmp");
		str=str+ext;
        pDocument->filename=str;

		struct Layer *tempptr;
	    tempptr=(struct Layer *)malloc(sizeof(struct Layer));
		tempptr->next=NULL;
		tempptr->pre=NULL;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;
		strcpy(tempptr->layername,"图层");
 	    strcat(tempptr->layername,pDocument->filename);

		pDocument->head=tempptr;
        pDocument->head->dib=new CRSImageBMP;
		pDocument->head->dib->SetDataPtr(&red);
		pDocument->head->dib->m_ReDraw=true;

		pDocument->curptr=pDocument->head;
	}

    pDocument->SetModifiedFlag(TRUE);
    CString sSplitCaption;
    pDocument->SetTitle(pDocument->filename);
    pDocument->UpdateAllViews(NULL);

    pDocument = (CRSImageStarDoc*) pDocTemplate->OpenDocumentFile(NULL);
    pDocument->m_Dib->SetDataPtr(&green);
    pDocument->size=size;

	if(pDocument->head==NULL)
	{
	    CString str;
		int count;
		count=filename.GetLength();
		str=filename.Left(count-4);

		CString ext;
		ext.Format("%s","(Green).bmp");
		str=str+ext;
        pDocument->filename=str;

		struct Layer *tempptr;
	    tempptr=(struct Layer *)malloc(sizeof(struct Layer));
		tempptr->next=NULL;
		tempptr->pre=NULL;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;

		strcpy(tempptr->layername,"图层");
 	    strcat(tempptr->layername,pDocument->filename);

		pDocument->head=tempptr;
        pDocument->head->dib=new CRSImageBMP;
		pDocument->head->dib->SetDataPtr(&green);
		pDocument->head->dib->m_ReDraw=true;
		pDocument->curptr=pDocument->head;
	}
    pDocument->SetModifiedFlag(TRUE);
    pDocument->SetTitle(pDocument->filename);
    pDocument->UpdateAllViews(NULL);

    pDocument = (CRSImageStarDoc*) pDocTemplate->OpenDocumentFile(NULL);
    pDocument->m_Dib->SetDataPtr(&blue);
    pDocument->size=size;

	if(pDocument->head==NULL)
	{
	    CString str;
		int count;
		count=filename.GetLength();
		str=filename.Left(count-4);

		CString ext;
		ext.Format("%s","(Blue).bmp");
		str=str+ext;
        pDocument->filename=str;

	    struct Layer *tempptr;
	    tempptr=(struct Layer *)malloc(sizeof(struct Layer));
		tempptr->next=NULL;
		tempptr->pre=NULL;
		tempptr->LUpoint=CPoint(0,0);
		tempptr->flagdraw=true;
		tempptr->flagwrite=true;

		strcpy(tempptr->layername,"图层");
 	    strcat(tempptr->layername,pDocument->filename);

		pDocument->head=tempptr;
        pDocument->head->dib=new CRSImageBMP;
		pDocument->head->dib->SetDataPtr(&blue);
		pDocument->head->dib->m_ReDraw=true;

		pDocument->curptr=pDocument->head;
	}
    pDocument->SetModifiedFlag(TRUE);
    pDocument->SetTitle(pDocument->filename);
    pDocument->UpdateAllViews(NULL);
  }
}

void CRSImageStarDoc::OnUpdateChannelsplit(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
    pCmdUI->Enable((m_Dib->filetype==6));	
}

//进行图象通道的合成
void CRSImageStarDoc::OnImagineChannelcom() 
{
	// TODO: Add your command handler code here
  CCombineDlg dlg;
  if (dlg.DoModal() == IDOK)
  {
	  CRSImageStarApp* pApp =(CRSImageStarApp*)AfxGetApp();
	  CWaitCursor wait;
	  POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
	  CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posTemplate);
 
	  CRSImageStarDoc *pDocument = (CRSImageStarDoc*) pDocTemplate->OpenDocumentFile(NULL);
	  if(pDocument->head==NULL)
	  {
		  CString str;
		  int count;
		  count=filename.GetLength();
		  str=filename.Left(count-4);
		  
		  CString ext;
		  ext.Format("%s","(Com).bmp");
		  str=str+ext;
		  pDocument->filename=str;
		  
		  struct Layer *tempptr;
		  tempptr=(struct Layer *)malloc(sizeof(struct Layer));
		  tempptr->next=NULL;
		  tempptr->pre=NULL;
		  tempptr->LUpoint=CPoint(0,0);
		  tempptr->flagdraw=true;
		  tempptr->flagwrite=true;
		  strcpy(tempptr->layername,"图层");
		  strcat(tempptr->layername,pDocument->filename);
		  
		  pDocument->head=tempptr;
		  pDocument->head->dib=new CRSImageBMP;
		  pDocument->head->dib->CombineChannels(dlg.m_pRedImage,dlg.m_pGreenImage,
			  dlg.m_pBlueImage);
		  pDocument->curptr=pDocument->head;
          pDocument->m_Dib->SetDataPtr(pDocument->head->dib);
		  pDocument->size=size;
	  } 
	  pDocument->SetModifiedFlag(TRUE);
      pDocument->SetTitle(pDocument->filename);
	  pDocument->UpdateAllViews(NULL);
  }
}

void CRSImageStarDoc::OnUpdateImagineChannelcom(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}


void CRSImageStarDoc::OnUpdateLayerDelete(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable((head->next!=NULL));
}

void CRSImageStarDoc::OnImageHismatch() 
{
	// TODO: Add your command handler code here
    CRSImage  *dib;
    
	BOOL bSuccess;
	CString ext,lpFileName;	
	CHisMatch dlg;
	if(dlg.DoModal()==IDOK)
	{
	    lpFileName=dlg.m_filename;
		ext=dlg.m_filename.Right(4);
	}
	else
		return;

	BeginWaitCursor();
    
	if(!ext.CompareNoCase(".JPG"))
	{
		dib=new CRSImageJPEG;
	    bSuccess = dib->Read(lpFileName);
	}
	else if(!ext.CompareNoCase(".TIF"))
	{
		dib=new CRSImageTIFF;
	    bSuccess = dib->Read(lpFileName);
	}
	else if(!ext.CompareNoCase(".BMP"))
	{
		dib=new CRSImageBMP;
	    bSuccess = dib->Read(lpFileName);
	}
	else
	{
		COpenBinDlg dlg;
        if(dlg.DoModal()==IDOK)
		{
			dib=new CRSImage;
			CRSImageBIN dib1;
			dib1.width=dlg.m_width;
			dib1.height=dlg.m_height;
            dib1.RedChannel=dlg.m_nRed;
			dib1.GreenChannel=dlg.m_nGreen;
			dib1.BlueChannel =dlg.m_nBlue;
			dib1.m_nheadsize=dlg.m_nCount;
			dib1.nByte=dlg.m_radio+1;
	        bSuccess = dib1.Read(lpFileName);
		    if(bSuccess)
			   dib->SetDataPtr(&dib1);
			else
				return ;
		}
		else
			return ;
	}

    if (!bSuccess)
	{
		ReportSaveLoadException(lpFileName, NULL,FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
		return ;
	}
    dib->GetHistogram();
	curptr->dib->nTempSize=dib->nTempSize;

	if(curptr->dib->filetype==TrueColorImage)
	{
		if(dib->filetype==TrueColorImage)
		{
			for(int i=0;i<=255;i++)
			{
				curptr->dib->nRed[i]   = dib->nRedChannel[i];
				curptr->dib->nGreen[i] = dib->nGreenChannel[i];
				curptr->dib->nBlue[i]  = dib->nBlueChannel[i];
			}
			curptr->dib->nMinTempRed   = dib->nMinRed;
			curptr->dib->nMinTempGreen = dib->nMinGreen;
			curptr->dib->nMinTempBlue  = dib->nMinBlue;
			curptr->dib->nMaxTempRed   = dib->nMaxRed;
			curptr->dib->nMaxTempGreen = dib->nMaxGreen;
			curptr->dib->nMaxTempBlue  = dib->nMaxBlue;
		}
		else
		{
			for(int i=0;i<=255;i++)
			{
				curptr->dib->nRed[i]   = dib->nRedChannel[i];
				curptr->dib->nGreen[i] = dib->nRedChannel[i];
				curptr->dib->nBlue[i]  = dib->nRedChannel[i];
			}
			curptr->dib->nMinTempRed   = dib->nMinRed;
			curptr->dib->nMinTempGreen = dib->nMinRed;
			curptr->dib->nMinTempBlue  = dib->nMinRed;
			curptr->dib->nMaxTempRed   = dib->nMaxRed;
			curptr->dib->nMaxTempGreen = dib->nMaxRed;
			curptr->dib->nMaxTempBlue  = dib->nMaxRed;
		}
	}
	else
	{
		for(int i=0;i<=255;i++)
			curptr->dib->nRed[i] = dib->nRedChannel[i];
		curptr->dib->nMinTempRed = dib->nMinRed;
		curptr->dib->nMaxTempRed = dib->nMaxRed;
	}
	if(m_Dib!=NULL)
	{
		BeginWaitCursor();
 		if(curptr->dib->HistogramValor())
        {
            SetModifiedFlag();
		}
		EndWaitCursor();
	}
	UpdateAllViews(NULL);

	delete dib;
						
}

void CRSImageStarDoc::OnImageNormal() 
{
	// TODO: Add your command handler code here
	if(curptr->dib->filetype==TrueColorImage)
	{
		curptr->dib->nMinTempRed=curptr->dib->nMinTempGreen=curptr->dib->nMinTempBlue=0;
		curptr->dib->nMaxTempRed=curptr->dib->nMaxTempGreen=curptr->dib->nMaxTempBlue=255;
	}
	else
	{
		curptr->dib->nMinTempRed=curptr->dib->nMinRed=0;
		curptr->dib->nMaxTempRed=curptr->dib->nMaxRed=255;

	}
	if(m_Dib!=NULL)
	{
		BeginWaitCursor();
 		if(curptr->dib->NormalDist(127.0,30.0))
            SetModifiedFlag();
		EndWaitCursor();
	}						
	UpdateAllViews(NULL);
}

void CRSImageStarDoc::OnImageHistogrmstat() 
{
	// TODO: Add your command handler code here
	CHistrogram dlg;
	dlg.DoModal();
}

⌨️ 快捷键说明

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