コード例 #1
0
void
ImageDocument::ShrinkToFit()
{
  if (!mImageContent) {
    return;
  }
  if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized &&
      !nsContentUtils::IsChildOfSameType(this)) {
    return;
  }

  // Keep image content alive while changing the attributes.
  nsCOMPtr<nsIContent> imageContent = mImageContent;
  nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(mImageContent);
  image->SetWidth(std::max(1, NSToCoordFloor(GetRatio() * mImageWidth)));
  image->SetHeight(std::max(1, NSToCoordFloor(GetRatio() * mImageHeight)));
  
  // The view might have been scrolled when zooming in, scroll back to the
  // origin now that we're showing a shrunk-to-window version.
  ScrollImageTo(0, 0, false);

  if (!mImageContent) {
    // ScrollImageTo flush destroyed our content.
    return;
  }

  SetModeClass(eShrinkToFit);
  
  mImageIsResized = true;
  
  UpdateTitleAndCharset();
}
コード例 #2
0
ファイル: ImageDocument.cpp プロジェクト: alphan102/gecko-dev
void
ImageDocument::ShrinkToFit()
{
  if (!mImageContent) {
    return;
  }
  if (GetZoomLevel() != mOriginalZoomLevel && mImageIsResized &&
      !nsContentUtils::IsChildOfSameType(this)) {
    // If we're zoomed, so that we don't maintain the invariant that
    // mImageIsResized if and only if its displayed width/height fit in
    // mVisibleWidth/mVisibleHeight, then we may need to switch to/from the
    // overflowingVertical class here, because our viewport size may have
    // changed and we don't plan to adjust the image size to compensate.  Since
    // mImageIsResized it has a "height" attribute set, and we can just get the
    // displayed image height by getting .height on the HTMLImageElement.
    HTMLImageElement* img = HTMLImageElement::FromContent(mImageContent);
    uint32_t imageHeight = img->Height();
    nsDOMTokenList* classList = img->ClassList();
    ErrorResult ignored;
    if (imageHeight > mVisibleHeight) {
      classList->Add(NS_LITERAL_STRING("overflowingVertical"), ignored);
    } else {
      classList->Remove(NS_LITERAL_STRING("overflowingVertical"), ignored);
    }
    ignored.SuppressException();
    return;
  }

  // Keep image content alive while changing the attributes.
  nsCOMPtr<Element> imageContent = mImageContent;
  nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(imageContent);
  image->SetWidth(std::max(1, NSToCoordFloor(GetRatio() * mImageWidth)));
  image->SetHeight(std::max(1, NSToCoordFloor(GetRatio() * mImageHeight)));
  
  // The view might have been scrolled when zooming in, scroll back to the
  // origin now that we're showing a shrunk-to-window version.
  ScrollImageTo(0, 0, false);

  if (!mImageContent) {
    // ScrollImageTo flush destroyed our content.
    return;
  }

  SetModeClass(eShrinkToFit);
  
  mImageIsResized = true;
  
  UpdateTitleAndCharset();
}
コード例 #3
0
ファイル: ImageDocument.cpp プロジェクト: alphan102/gecko-dev
void
ImageDocument::ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage)
{
  float ratio = GetRatio();

  if (restoreImage) {
    RestoreImage();
    FlushPendingNotifications(FlushType::Layout);
  }

  nsCOMPtr<nsIPresShell> shell = GetShell();
  if (!shell) {
    return;
  }

  nsIScrollableFrame* sf = shell->GetRootScrollFrameAsScrollable();
  if (!sf) {
    return;
  }

  nsRect portRect = sf->GetScrollPortRect();
  sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(aX/ratio) - portRect.width/2,
                       nsPresContext::CSSPixelsToAppUnits(aY/ratio) - portRect.height/2),
               nsIScrollableFrame::INSTANT);
}
コード例 #4
0
bool CTuningBase::CreateGroupGeometric(const NOTEINDEXTYPE& s, const RATIOTYPE& r, const NOTEINDEXTYPE& startindex)
//-----------------------------------------------------------------------------------------------------------------
{
	if(s < 1 || r <= 0 || startindex < GetValidityRange().first)
		return true;

	std::vector<RATIOTYPE> v;
	v.reserve(s);
	for(NOTEINDEXTYPE i = startindex; i<startindex+s; i++)
		v.push_back(GetRatio(i));
	return CreateGroupGeometric(v, r, GetValidityRange(), startindex);
}
コード例 #5
0
ファイル: Scanner.cpp プロジェクト: SulfredLee/OpneCVStation
int Scanner::main(int argc, _TCHAR* argv[])
{
	if (argc < 5){
		std::cerr << "Usage:\n"
			<< "Scanner.exe -i imgFile -s shiftValue\n";
		return -1;
	}

	ParsingCMD cmd;
	cmd.Set("-i"); cmd.Set("-s");
	cmd.DoParsing(argc, argv);

	fileName = cmd["-i"];
	shiftValue = std::atoi(cmd["-s"].c_str());

	image = cv::imread(fileName, CV_LOAD_IMAGE_COLOR);
	GetRatio();
	image.copyTo(orig);
	cv::resize(image, image, cv::Size(), invRatio, invRatio);


	cv::cvtColor(image, gray, CV_BGR2GRAY);
	cv::GaussianBlur(gray, gray, cv::Size(5, 5), 0);
	int temptemp = 20;
	cv::Canny(gray, edged, temptemp, temptemp * 2);


	cv::findContours(edged, cnts, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
	std::sort(cnts.begin(), cnts.end(), Scanner::SortVecPoint);
	//DrawCont(cnts);

	for (size_t i = 0; i < cnts.size(); i++){
		double peri = cv::arcLength(cnts[i], true);
		std::vector<cv::Point> approx;
		cv::approxPolyDP(cv::Mat(cnts[i]), approx, 0.02 * peri, true);

		if (approx.size() == 4){
			screenCnt.push_back(approx);
			break;
		}
	}

	warped = four_point_transform(orig, screenCnt[0], ratio);

	cv::cvtColor(warped, warped, CV_BGR2GRAY);
	cv::adaptiveThreshold(warped, warped, 250, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 11, shiftValue);
	cv::imwrite("out" + fileName, warped);

	return 0;
}
コード例 #6
0
bool CTuningBase::Multiply(const RATIOTYPE& r)
//--------------------------------------------
{
	if(r <= 0 || !MayEdit(EM_RATIOS))
		return true;

	//Note: Multiplying ratios by constant doesn't
	//change, e.g. 'geometricness' status.
	VRPAIR vrp = GetValidityRange();
	for(NOTEINDEXTYPE i = vrp.first; i<vrp.second; i++)
	{
		if(ProSetRatio(i, r*GetRatio(i)))
			return true;
	}
	return false;
}
コード例 #7
0
void CBackImageManager::SetRenderTex( eTEX_TYPE eType )
{
	m_nCurrentType = eType;

	m_pRenderTex = TexDataAt(eType);

	if (m_pRenderTex == NULL)
		return;

	FLOAT fTexW = m_pRenderTex->GetWidth();
	FLOAT fTexH = m_pRenderTex->GetHeight();

	m_nWidth  = CUIManager::getSingleton()->GetWidth();
	m_nHeight = CUIManager::getSingleton()->GetHeight();

	eRATIO eRatio = GetRatio(m_nWidth, m_nHeight);

	int nRatioWidth = m_nWidth;
	int nRatioHeight = m_nHeight;

	m_fTexU0 = 0.0f;
	m_fTexV0 = 0.0f;
	m_fTexU1 = DEF_TEX_WIDTH / fTexW;
	m_fTexV1 = DEF_TEX_HEIGHT / fTexH;

	if (eRatio == eRATIO_4_3)
	{
		nRatioWidth = (DEF_TEX_WIDTH - (DEF_TEX_HEIGHT * 4.f / 3.f)) * 0.5f;
		m_fTexU0 = nRatioWidth / fTexW;
		m_fTexU1 = ((DEF_TEX_WIDTH - (FLOAT)nRatioWidth)) / fTexW;
	}
	else if (eRatio == eRATIO_5_4)
	{
		nRatioWidth = (DEF_TEX_WIDTH - (DEF_TEX_HEIGHT * 5.f / 4.f)) * 0.5f;
		m_fTexU0 = nRatioWidth / fTexW;
		m_fTexU1 = ((DEF_TEX_WIDTH - (FLOAT)nRatioWidth)) / fTexW;
	}
	else if (eRatio == eRATIO_16_9)
	{
		nRatioHeight = (DEF_TEX_HEIGHT - (DEF_TEX_WIDTH * 9.f / 16.f)) * 0.5f;
		m_fTexV0 = (FLOAT)nRatioHeight / fTexH;
		m_fTexV1 = ((DEF_TEX_HEIGHT - (FLOAT)nRatioHeight)) / fTexH;
	}
}
コード例 #8
0
float CBackImageManager::GetRatioCamera( float fFov, int nWidth, int nHeight )
{
	eRATIO eRatio = GetRatio(nWidth, nHeight);

	float fTan = fFov * 0.5f;	// eRATIO_16_10

	int nResolutionIdx = GetResolutionIndex();

	float fDis = DEF_CAMERA_DISTANCE;
		
	if (eRatio == eRATIO_4_3)
		fDis = DEF_CAMERA_DISTANCE_4_3;
	if (eRatio == eRATIO_5_4)
		fDis = DEF_CAMERA_DISTANCE_5_4;

	float fl = 8.f + (fDis / Tan(fTan));

	return fl;
}
コード例 #9
0
void 
ImageDocument::UpdateTitleAndCharset()
{
  nsAutoCString typeStr;
  nsCOMPtr<imgIRequest> imageRequest;
  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
  if (imageLoader) {
    imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                            getter_AddRefs(imageRequest));
  }
    
  if (imageRequest) {
    nsXPIDLCString mimeType;
    imageRequest->GetMimeType(getter_Copies(mimeType));
    ToUpperCase(mimeType);
    nsXPIDLCString::const_iterator start, end;
    mimeType.BeginReading(start);
    mimeType.EndReading(end);
    nsXPIDLCString::const_iterator iter = end;
    if (FindInReadable(NS_LITERAL_CSTRING("IMAGE/"), start, iter) && 
        iter != end) {
      // strip out "X-" if any
      if (*iter == 'X') {
        ++iter;
        if (iter != end && *iter == '-') {
          ++iter;
          if (iter == end) {
            // looks like "IMAGE/X-" is the type??  Bail out of here.
            mimeType.BeginReading(iter);
          }
        } else {
          --iter;
        }
      }
      typeStr = Substring(iter, end);
    } else {
      typeStr = mimeType;
    }
  }

  nsXPIDLString status;
  if (mImageIsResized) {
    nsAutoString ratioStr;
    ratioStr.AppendInt(NSToCoordFloor(GetRatio() * 100));

    const char16_t* formatString[1] = { ratioStr.get() };
    mStringBundle->FormatStringFromName(MOZ_UTF16("ScaledImage"),
                                        formatString, 1,
                                        getter_Copies(status));
  }

  static const char* const formatNames[4] = 
  {
    "ImageTitleWithNeitherDimensionsNorFile",
    "ImageTitleWithoutDimensions",
    "ImageTitleWithDimensions2",
    "ImageTitleWithDimensions2AndFile",
  };

  MediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
                                       mImageWidth, mImageHeight, status);
}
コード例 #10
0
void Plot_McollRatio(TString file, TString fakefile, TString sample, TString SR, bool subtractFakes)
{

	SetAtlasStyle();
	#ifdef __CINT__
	  gROOT->LoadMacro("AtlasUtils.C");
	#endif

  	double xmin = 50;
  	double xmax = 400;


  	TFile* f = new TFile(file);
  	TFile* fakef = new TFile(fakefile);

  	TH1D* hME;
  	TH1D* hEM;

  	//if (isScaled){
//  		hME =(TH1D*)f->Get("ME_scaled");//nom/ME_McollHiggs_Unblind");
//  		hEM =(TH1D*)f->Get("EM");//nom/EM_McollHiggs_Unblind");
//  		hME_orig = (TH1D*)f->Get("ME_original");
//  		hEM_orig = (TH1D*)f->Get("EM_original");
  	//}
  	//else{
  		hME =(TH1D*)f->Get("nom/ME_McollHiggs_Unblind");
  		hEM =(TH1D*)f->Get("nom/EM_McollHiggs_Unblind");
  	//}

  	if (subtractFakes){
  		TH1D* hME_fake = (TH1D*)fakef->Get("nom/ME_McollHiggs_Unblind");
  		TH1D* hEM_fake = (TH1D*)fakef->Get("nom/EM_McollHiggs_Unblind");

  		hME->Add(hME_fake,-1);
  		hEM->Add(hEM_fake,-1);
 	}
  	hEM->SetMarkerStyle(8); hEM->SetMarkerSize(0.7);
  	hEM->SetLineColor(kPink + 8);hEM->SetOption("e1");
  	hEM->SetMarkerColor(kPink + 8);
  	hME->SetMarkerStyle(8); hME->SetMarkerSize(0.7);
  	hME->SetLineColor(kTeal - 6);hME->SetOption("e1");
  	hME->SetMarkerColor(kTeal - 6);
  	hME->GetXaxis()->SetLabelOffset(0); hME->GetXaxis()->SetLabelSize(0);
  	hEM->GetXaxis()->SetLabelOffset(0); hEM->GetXaxis()->SetLabelSize(0);
  	hEM->GetXaxis()->SetRangeUser(xmin,xmax);   hME->GetXaxis()->SetRangeUser(xmin,xmax);
  	hEM->GetYaxis()->SetTitleOffset(1.0);
  	hME->GetYaxis()->SetTitleOffset(1.0);

//  	hEM_orig->SetMarkerStyle(8); hEM_orig->SetMarkerSize(0.7);
//  	hEM_orig->SetLineColor(kPink + 8);hEM_orig->SetOption("e1");
//  	hEM_orig->SetMarkerColor(kPink + 8);
//  	hME_orig->SetMarkerStyle(8); hME_orig->SetMarkerSize(0.7);
//  	hME_orig->SetLineColor(kTeal - 6);hME_orig->SetOption("e1");
//  	hME_orig->SetMarkerColor(kTeal - 6);
//  	hME_orig->GetXaxis()->SetLabelOffset(0); hME_orig->GetXaxis()->SetLabelSize(0);
//  	hEM_orig->GetXaxis()->SetLabelOffset(0); hEM_orig->GetXaxis()->SetLabelSize(0);
//  	hEM_orig->GetXaxis()->SetRangeUser(xmin,xmax);   hME_orig->GetXaxis()->SetRangeUser(xmin,xmax);
//  	hEM_orig->GetYaxis()->SetTitleOffset(1.0);
//  	hME_orig->GetYaxis()->SetTitleOffset(1.0);

  	double numEM = hEM->Integral();
  	double numME = hME->Integral();

  	cout<<"# entries EM = " << numEM << endl;
  	cout<<"# entries ME = " << numME << endl;

//  	TH1D* ratio2 = GetRatio(hEM_orig,hME_orig,xmin,xmax);
//  	TH1D* diff2 = GetDiff(hEM_orig,hME_orig,xmin,xmax);

  	TH1D* ratio = GetRatio(hEM,hME,xmin,xmax);
  	TH1D* diff = GetDiff(hEM,hME,xmin,xmax);

  	TLegend* leg = new TLegend(0.6,0.45,0.75,0.55);
  	leg->SetFillColor(kWhite); leg->SetBorderSize(1); leg->SetLineColor(0); leg->SetTextFont(42);
  	leg->SetTextSize(.05);

  	TLine* line1 = new TLine(xmin,1,xmax,1); line1->SetLineColor(kRed); line1->SetLineStyle(2);
  	TLine* line14 = new TLine(xmin,1.5,xmax,1.5); line14->SetLineStyle(9);
  	line14->SetLineColor(kBlack);
  	TLine* line13 = new TLine(xmin,2./3,xmax,2./3); line13->SetLineStyle(2);
  	line13->SetLineColor(kRed);
  	TLine* line12 = new TLine(xmin,2,xmax,2); line12->SetLineStyle(9);
  	line12->SetLineColor(kBlack);
  	TLine* line15 = new TLine(xmin,0.5,xmax,0.5); line15->SetLineStyle(9);
  	line15->SetLineColor(kBlack);
  	TLine* line2 = new TLine(xmin,0,xmax,0); line2->SetLineColor(kBlack); line2->SetLineStyle(9);

  	TLine* vline1 = new TLine(100,0,100,3000); vline1->SetLineStyle(2);
  	TLine* vline2 = new TLine(150,0,150,3000); vline2->SetLineStyle(2);

  	TCanvas* c0 = new TCanvas("mcoll ","mcoll ",600,600); c0=c0;
  	TPad *pad1 =  new TPad("pad1", "12<L1<15",0.0,0.2,1,1.0,21); pad1->SetMargin(0.1,0.1,0.02,0.2);
  	TPad *pad2 =  new TPad("pad2", "ratio",   0.0,0,1,0.2,21); pad2->SetMargin(0.1,0.1,0.3,0.02);
//  	TPad *pad3 =  new TPad("pad3", "diff",    0.0,0,1,0.2,21); pad3->SetMargin(0.1,0.1,0.3,0.02);

  	pad1->SetFillColor(0);pad2->SetFillColor(0);//pad3->SetFillColor(0);
  	pad1->Draw(); pad2->Draw();//pad3->Draw();


  	pad1->cd();

	#ifdef __CINT__
  		gROOT->LoadMacro("AtlasLabels.C");
	#endif

  	leg->AddEntry(hME,"#mue","le");
  	leg->AddEntry(hEM,"e#mu","le");


  	hEM->Draw("e1"); hME->Draw("e1 sames");
  	vline1->Draw(); vline2->Draw();


  	pad2->cd();
  	ratio->Draw();
  	line14->Draw();line15->Draw();line1->Draw();

//  	pad3->cd();
//  	diff->Draw();
//  	line2->Draw();

  	pad1->cd();
  	myText(0.5,0.65,1,"#int L dt = 20.3 fb^{-1}  #sqrt{s} = 8 TeV");
  	myText(0.6,0.35,1,sample);
  	myText(0.6,0.25,1,SR);

  	ATLASLabel(0.62,0.75,"Internal");

  	leg->Draw();


  	c0->Update();

//  	TCanvas* c1 = new TCanvas("mcoll original","mcoll original",600,600); c0=c0;
//  	TPad *pad1_2 =  new TPad("pad1", "12<L1<15",0.0,0.4,1,1.0,21); pad1_2->SetMargin(0.1,0.1,0.02,0.2);
//  	TPad *pad2_2 =  new TPad("pad2", "ratio",   0.0,0.2,1,0.4,21); pad2_2->SetMargin(0.1,0.1,0.02,0.02);
//  	TPad *pad3_2 =  new TPad("pad3", "diff",    0.0,0,1,0.2,21); pad3_2->SetMargin(0.1,0.1,0.3,0.02);
//
//  	pad1_2->SetFillColor(0);pad2_2->SetFillColor(0);pad3_2->SetFillColor(0);
//  	pad1_2->Draw(); pad2_2->Draw();pad3_2->Draw();
//
//
//  	pad1_2->cd();

//  	hEM_orig->Draw("e1"); hME_orig->Draw("e1 sames");
//  	vline1->Draw(); vline2->Draw();


//  	pad2_2->cd();
//  	ratio2->Draw();
//  	line14->Draw();line15->Draw();line1->Draw();

//  	pad3_2->cd();
//  	diff2->Draw();
//  	line2->Draw();

//  	pad1_2->cd();
//  	myText(0.5,0.65,1,"#int L dt = 20.3 fb^{-1}  #sqrt{s} = 8 TeV");
//  	myText(0.6,0.35,1,sample);
//
//  	ATLASLabel(0.62,0.75,"Internal");
//
//  	leg->Draw();
//
//
//  	c1->Update();



  return;
}
コード例 #11
0
/*******************************************************************
 * Function Name: isArmCarry
 * Return Type 	: std::pair<bool, double>
 * Created On	: Oct 21, 2013
 * Created By 	: hrushi
 * Comments		: Check if the arm is carry or not carry
 * Arguments	: enclosing_method_arguments
 *******************************************************************/
pr_score DetectByPose::isArmCarry( const string PartType, const Contour& Ctr, vector<double>& vAllScore ) const
{
	pr_score RetPair;

	char MapKey = (PartType == "lArm" )? 'm' : 'c';

	PoseEM DragCarryEM, WornCarryEM, NoCarryEM;

	if( PartType == "lArm")
	{
		WornCarryEM = m_Map_strPoseEM.at(LEFT_WORN_POSE_FEATURE_FILE);
		DragCarryEM = m_Map_strPoseEM.at(LEFT_DRAG_POSE_FEATURE_FILE);
		NoCarryEM 	= m_Map_strPoseEM.at(LEFT_NOCARRY_POSE_FEATURE_FILE);

	}
	else
	{
		WornCarryEM = m_Map_strPoseEM.at(RIGHT_WORN_POSE_FEATURE_FILE);
		DragCarryEM = m_Map_strPoseEM.at(RIGHT_DRAG_POSE_FEATURE_FILE);
		NoCarryEM 	= m_Map_strPoseEM.at(RIGHT_NOCARRY_POSE_FEATURE_FILE);

	}

	ColorImg DispImg = m_Pose.OverlayExtn(m_ProbeImg, MapKey, Ctr);

	const vector<double> PoseFeature = m_Pose.CalcPoseFeature(MapKey, Ctr );

	double dWornLog(0), dDragLog(0), dPersonLog(0);
	double dWornRatio = GetRatio(PoseFeature, WornCarryEM, NoCarryEM, dWornLog, dPersonLog); //Note: dPersonLog value will be the same, because we have only one EM
	double dDragRatio = GetRatio(PoseFeature, DragCarryEM, NoCarryEM, dDragLog, dPersonLog);

	//---------- Order or push_back important ---------- //
	vAllScore.push_back(dWornLog);
	vAllScore.push_back(dDragLog);
	vAllScore.push_back(dPersonLog);

	vAllScore = LogToProb(vAllScore);

	if((dWornRatio > 1 ) || (dDragRatio > 1)) //Carry probability is more than no-carry probability
	{
		if( dWornRatio > dDragRatio )
		{
			RetPair.first 	= WORN_CARRY_LABEL;
			RetPair.second	= dWornLog;

			//DispImg.Overlay(Ctr, DISP_DELAY, COLOR_RED, Args() ).Display(DISP_DELAY);
			cout << PartType << " : " << "Worn" << endl;
		}
		else
		{
			RetPair.first 	= DRAG_CARRY_LABEL;
			RetPair.second 	= dDragLog;
			//DispImg.Overlay(Ctr, DISP_DELAY, COLOR_GREEN, Args() ).Display(DISP_DELAY);
			cout << PartType << " : " << "Drag" << endl;
		}
	}
	else
	{
		RetPair.first	= PERSON_LABEL;
		RetPair.second	= dPersonLog;
		//DispImg.Overlay(Ctr, DISP_DELAY, COLOR_BLUE, Args() ).Display(DISP_DELAY);
		cout << PartType << " : " << "Person" << endl;
	}

	return RetPair;
}
コード例 #12
0
ファイル: KData.cpp プロジェクト: darwinbeing/trade
void CKData::ConvertXDR( BOOL bUP, DWORD dateAutoDRBegin, double dAutoDRLimit )
{
	CDRData	drtemp;
	drtemp	=	m_drdata;
	drtemp.Sort( );

	if( m_pData )
	{
		delete [] (BYTE*)m_pData;
		m_nSize	=	m_nMaxSize	=	0;
		m_pData	=	NULL;
	}

	if( NULL == m_pDataOriginal || 0 == m_nSizeOriginal )
		return;
	
/*	if( drtemp.GetSize() == 0 )
	{
		SetSize( m_nSizeOriginal );
		if( m_pData )
			memcpy( m_pData, m_pDataOriginal, sizeof(KDATA)*m_nSize );
		return;
	}
*/
	dAutoDRLimit	=	dAutoDRLimit / 100;

	if( bUP )
	{
		SetSize( 0, m_nSizeOriginal );
		int	drPos	=	0;
		float	fRatio	=	1.000000;
		for( int i=0; i<m_nSizeOriginal; i++ )
		{
			KDATA	& kd = m_pDataOriginal[i];
			KDATA	newkd	=	kd;
			
			if( drPos < drtemp.GetSize() && ToDayDate(kd.m_date) >= drtemp.ElementAt(drPos).m_date )
			{
				if( i > 0 )
				{
					KDATA	kdLast	=	m_pDataOriginal[i-1];
					fRatio	=	fRatio * GetRatio( kdLast.m_fClose, drtemp.ElementAt(drPos) );
				}
				
				drPos	++;
			}
			else if( ToDayDate(kd.m_date) >= dateAutoDRBegin && i > 0 )	//	Auto XDR
			{
				KDATA	kdLast	=	m_pDataOriginal[i-1];
				if( kdLast.m_fClose > 1e-4 && kd.m_fOpen < kdLast.m_fClose
					&& fabs(kd.m_fOpen/kdLast.m_fClose-1) > dAutoDRLimit )
					fRatio	=	fRatio * kd.m_fOpen / kdLast.m_fClose;
			}

			newkd.m_fOpen	=	(kd.m_fOpen / fRatio);
			newkd.m_fHigh	=	(kd.m_fHigh / fRatio);
			newkd.m_fLow	=	(kd.m_fLow / fRatio);
			newkd.m_fClose	=	(kd.m_fClose / fRatio);
			newkd.m_fVolume	=	(kd.m_fVolume * fRatio);
			Add( newkd );
		}
	}
	else
	{
		SetSize( m_nSizeOriginal );
		int	drPos	=	drtemp.GetSize()-1;
		float	fRatio	=	1.000000;
		for( int i=m_nSizeOriginal-1; i>=0; i-- )
		{
			KDATA	& kd = m_pDataOriginal[i];
			KDATA	newkd	=	kd;
			
			if( drPos >= 0 && ToDayDate(kd.m_date) < drtemp.ElementAt(drPos).m_date )
			{
				if( i < m_nSizeOriginal-1 )
					fRatio	=	fRatio * GetRatio( kd.m_fClose, drtemp.ElementAt(drPos) );
				
				drPos	--;
			}
			else if( ToDayDate(kd.m_date) >= dateAutoDRBegin && i+1 < m_nSizeOriginal )	//	Auto XDR
			{
				KDATA	kdNext	=	m_pDataOriginal[i+1];
				if( kdNext.m_fOpen > 1e-4 && kdNext.m_fOpen < kd.m_fClose
					&& fabs(kdNext.m_fOpen/kd.m_fClose-1) > dAutoDRLimit )
					fRatio	=	fRatio * kdNext.m_fOpen / kd.m_fClose;
			}

			newkd.m_fOpen	=	(kd.m_fOpen * fRatio);
			newkd.m_fHigh	=	(kd.m_fHigh * fRatio);
			newkd.m_fLow	=	(kd.m_fLow * fRatio);
			newkd.m_fClose	=	(kd.m_fClose * fRatio);
			newkd.m_fVolume	=	(kd.m_fVolume / fRatio);
			SetAt( i, newkd );
		}
	}
}
コード例 #13
0
ファイル: Area.cpp プロジェクト: nairnj/nairn-mpm-fea
// Mesh an area that has been checked already as valid and is quadrilateral
// throws std::bad_alloc
const char *Area::MeshArea(void)
{
	int i;
	int eNode[MaxElNd];
	
	// space for area nodes and element object
	areaNode=new Vector[2*numPaths];
	for(i=0;i<8;i++) eNode[i]=i+1;
	areaElem=new EightNodeIsoparam(1,eNode,1,(double)0.0,(double)0.0);
	
	// put nodes at the corners
	for(i=0;i<numPaths;i++)
	{	edges[i]->FirstKeypointToNode();
		edges[i]->GetFirstAndMidXY(&areaNode[i],&areaNode[i+numPaths]);
	}
		
	// place nodes along the edges
	for(i=0;i<numPaths;i++)
	{	if(!edges[i]->IsMeshed())
		{	// Get line in dimensionless coordinates
			double x1=1.,y1=1.,x2=1.,y2=1.;
			switch(i)
			{	case 0:
					x1=y1=y2=-1;
					break;
				case 1:
					y1=-1;
					break;
				case 2:
					x2=-1;
					break;
				case 3:	
					x1=x2=y2=-1;
					break;
				default:
					break;
			}
			
			// Do main nodes (note: 1 interval is special case)
			if(edges[i]->intervals==1)
			{	// Only 1 interval - no need to get nodes
				edges[i]->firstMainNode=0;
			}
			else
			{	edges[i]->firstMainNode=theNodes->NextNodeNumber();
				MeshLine(x1,y1,x2,y2,edges[i]->ratio,edges[i]->intervals,FALSE);
			}
			
			/* Do mid side nodes */
			if(theElems->HasMidsideNodes())
			{	edges[i]->firstMidsideNode=theNodes->NextNodeNumber();
				MeshLine(x1,y1,x2,y2,edges[i]->ratio,edges[i]->intervals,TRUE);
			}
		}
	}
	
	/*-------------------------------------------------------------------
	 	Use the following section when the numbers of elements are not
	 		that same on opposite sides
		Divide element as follows:
		 
			   _____na__________
			  |\               |
			  |  \+5           |+3      na, nb, nc are numbers of intervals
			  |    \ nc        5 nc                
			  |      \         |        1. create new keypoints (#'s on lines)
		  nb  |        6___+6__3        2. create new paths (+numbers
			  |  1st    |  na  |+2      3. Call MeshArea recursively for the
			  |   nb  +4|      4 nb          newly created areas with equal
			  |   +0    |   +1 |             interval numbers on opposites sides
			  -----1----0---2--
				  nc         na
	-------------------------------------------------------------------*/
	if(edges[0]->intervals!=edges[2]->intervals)
	{	// area intervals (have been ordered such that n1>n3, which implies n2>n4)
		int n1=edges[0]->intervals;
		int n3=edges[2]->intervals;
		int n4=edges[3]->intervals;
		int nc=n1-n3;
		int na=n3;
		int nb=n4;
		
		// keypoint at junction of two new paths along path 1
		double targ,t1arg,x1arg,x2arg,y1arg,y2arg,xkey,ykey;
		Keypoint *addedKeys[7];
		FindPtOnLine((double)-1.,(double)-1.,(double)1.,(double)-1.,edges[0]->ratio,
				edges[0]->intervals,nc,&targ,&x1arg,&x2arg,&y1arg,&y2arg);
		t1arg=targ;
		LineLocate(targ,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[0]=new Keypoint("",xkey,ykey);
		addedKeys[0]->node=edges[0]->firstMainNode+(nc-1)*edges[0]->nodeIncrement;
		
		// Create keypoint in middle of added path 0
		LineLocate((targ-1.)/2.,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[1]=new Keypoint("",xkey,ykey);
		
		// Create keypoint in middle of added path 1 */
		LineLocate((1.+targ)/2.,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[2]=new Keypoint("",xkey,ykey);
		
		// keypoint at junction of two new paths along path 2
		FindPtOnLine((double)1.,(double)-1.,(double)1.,(double)1.,edges[1]->ratio,
				edges[1]->intervals,nb,&targ,&x1arg,&x2arg,&y1arg,&y2arg);
		LineLocate(targ,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[3]=new Keypoint("",xkey,ykey);
		addedKeys[3]->node=edges[1]->firstMainNode+(nb-1)*edges[1]->nodeIncrement;
		
		// Create keypoint in middle of added path 2
		LineLocate((targ-1.)/2.,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[4]=new Keypoint("",xkey,ykey);
		
		// Create keypoint in middle of added path 3
		LineLocate((1.+targ)/2.,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[5]=new Keypoint("",xkey,ykey);
		
		// keypoint at middle of area
		FindPtOnLine(t1arg,(double)-1.,t1arg,(double)1.,edges[1]->ratio,
				edges[1]->intervals,nb,&targ,&x1arg,&x2arg,&y1arg,&y2arg);
		LineLocate(targ,x1arg,x2arg,y1arg,y2arg,&xkey,&ykey);
		addedKeys[6]=new Keypoint("",xkey,ykey);
		
		// First new path along path 1
		Path *addedPaths[7];
		double r,a1,a4;
		GetLineParameters(edges[0]->intervals,edges[0]->ratio,&r,&a1);
		addedPaths[0]=new Path("",nc,GetRatio(nc,r));
		addedPaths[0]->SetKeys(edges[0]->FirstKeypoint(),addedKeys[1],addedKeys[0]);
		addedPaths[0]->firstMainNode=edges[0]->firstMainNode;
		addedPaths[0]->firstMidsideNode=edges[0]->firstMidsideNode;
		addedPaths[0]->nodeIncrement=edges[0]->nodeIncrement;
		edges[0]->subPath[0]=addedPaths[0];
		
		// Second new path along path 1
		addedPaths[1]=new Path("",na,GetRatio(na,r));
		addedPaths[1]->SetKeys(addedKeys[0],addedKeys[2],edges[0]->LastKeypoint());
		addedPaths[1]->firstMainNode=edges[0]->firstMainNode+nc*edges[0]->nodeIncrement;
		addedPaths[1]->firstMidsideNode=edges[0]->firstMidsideNode+nc*edges[0]->nodeIncrement;
		addedPaths[1]->nodeIncrement=edges[0]->nodeIncrement;
		edges[0]->subPath[1]=addedPaths[1];
		
		// First new path along path 2
		GetLineParameters(edges[1]->intervals,edges[1]->ratio,&r,&a4);
		addedPaths[2]=new Path("",nb,GetRatio(nb,r));
		addedPaths[2]->SetKeys(edges[1]->FirstKeypoint(),addedKeys[4],addedKeys[3]);
		addedPaths[2]->firstMainNode=edges[1]->firstMainNode;
		addedPaths[2]->firstMidsideNode=edges[1]->firstMidsideNode;
		addedPaths[2]->nodeIncrement=edges[1]->nodeIncrement;
		edges[1]->subPath[0]=addedPaths[2];

		// Second new path along path 2
		addedPaths[3]=new Path("",nc,GetRatio(nc,r));
		addedPaths[3]->SetKeys(addedKeys[3],addedKeys[5],edges[1]->LastKeypoint());
		addedPaths[3]->firstMainNode=edges[1]->firstMainNode+nb*edges[1]->nodeIncrement;
		addedPaths[3]->firstMidsideNode=edges[1]->firstMidsideNode+nb*edges[1]->nodeIncrement;
		addedPaths[3]->nodeIncrement=edges[1]->nodeIncrement;
		edges[1]->subPath[1]=addedPaths[3];
		
		// New Path from path 1 to central point
		addedPaths[4]=new Path("",nb,addedPaths[2]->ratio);
		addedPaths[4]->SetKeys(addedKeys[0],addedKeys[6],NULL);
		
		// New Path from central point to upper-left corner
		GetLineParameters(addedPaths[0]->intervals,addedPaths[0]->ratio,&r,&a1);
		GetLineParameters(addedPaths[3]->intervals,addedPaths[3]->ratio,&r,&a4);
		x2arg=addedKeys[0]->x-(edges[0]->FirstKeypoint())->x;
		y2arg=addedKeys[0]->y-(edges[0]->FirstKeypoint())->y;
		double p1d1=a1*a1*(x2arg*x2arg+y2arg*y2arg);
		double p1d2=p1d1/(addedPaths[0]->ratio*addedPaths[0]->ratio);
		x2arg=(edges[1]->LastKeypoint())->x-addedKeys[3]->x;
		y2arg=(edges[1]->LastKeypoint())->y-addedKeys[3]->y;
		double p4d1=a4*a4*(x2arg*x2arg+y2arg*y2arg);
		double p4d2=p4d1/(addedPaths[3]->ratio*addedPaths[3]->ratio);
		double ratio=sqrt(p1d2 + p4d1)/sqrt(p1d1 + p4d2);
		addedPaths[5]=new Path("",nc,ratio);
		addedPaths[5]->SetKeys(addedKeys[6],edges[3]->FirstKeypoint(),NULL);

		// New Path from path 2 to central point
		addedPaths[6]=new Path("",na,1./addedPaths[1]->ratio);
		addedPaths[6]->SetKeys(addedKeys[3],addedKeys[6],NULL);
		
		// clear and store items
		delete [] areaNode;
		delete areaElem;
		areaNode=NULL;
		areaElem=NULL;
		Path *oldEdges[4];
		for(i=0;i<=3;i++) oldEdges[i]=edges[i];
		
		// Call MeshArea three times (do not flip 1st or 3rd areas)
		bool oldFlip=theElems->FlipTriangles();
		theElems->SetFlipTriangles("0");
		edges[0]=addedPaths[0];
		edges[1]=addedPaths[4];
		edges[2]=addedPaths[5];
		edges[3]=oldEdges[3];
		const char *msg=MeshArea();
		if(msg!=NULL) return msg;
		
		theElems->SetFlipTriangles(oldFlip);
		edges[0]=addedPaths[1];
		edges[1]=addedPaths[2];
		edges[2]=addedPaths[6];
		edges[3]=addedPaths[4];
		edges[3]->ReorientPath();
		msg=MeshArea();
		if(msg!=NULL) return msg;

		theElems->SetFlipTriangles("0");
		edges[0]=addedPaths[6];
		edges[1]=addedPaths[3];
		edges[2]=oldEdges[2];
		edges[3]=addedPaths[5];
		edges[0]->ReorientPath();
		edges[3]->ReorientPath();
		msg=MeshArea();
		if(msg!=NULL) return msg;
		
		theElems->SetFlipTriangles(oldFlip);		// restore
		// add to list so they get deleted when no longer needed
		for(i=0;i<=6;i++)
		{	keyPts->AddObject(addedKeys[i]);
			paths->AddObject(addedPaths[i]);
		}
		return NULL;
	}

	/* Mesh nodes that are interior to the area
	*/
	double rLeft,aLeft,rRight,aRight;
	int firstInterior=0,firstInteriorMidside=0;
	double yLeft,yRight,yLLast,yRLast;
	double ratio,botFraction,yLeftLast,yRightLast,yLeftMid,yRightMid;
	
	// Linear interpolation of ratios
	double ratioTop=1./edges[2]->ratio;
	double ratioBot=edges[0]->ratio;
	
	// Define interval spacing along left and right edges
	GetLineParameters(edges[3]->intervals,1/edges[3]->ratio,&rLeft,&aLeft);
	GetLineParameters(edges[1]->intervals,edges[1]->ratio,&rRight,&aRight);
	
	// Do main nodes interior to area (if any are there) */
	if(edges[3]->intervals>1 && edges[0]->intervals>1)
	{	firstInterior=theNodes->NextNodeNumber();
		
		// Loop over intervals
		yLeft=yRight=-1.;
		yLLast=aLeft;
		yRLast=aRight;
		for(i=1;i<edges[3]->intervals;i++)
		{	yLeft+=yLLast;
			yLLast*=rLeft;
			yRight+=yRLast;
			yRLast*=rRight;
			botFraction=(1.-(yLeft+yRight)/2.)/2.;
			ratio=botFraction*ratioBot+(1-botFraction)*ratioTop;
			MeshLine((double)-1.,yLeft,(double)1.,yRight,ratio,edges[0]->intervals,FALSE);
		}
	}

	// Do mid side nodes (if needed)
	if(theElems->HasMidsideNodes() && (edges[0]->intervals>1 || edges[3]->intervals>1))
	{	firstInteriorMidside=theNodes->NextNodeNumber();
		
		// Loop over intervals
		yLeft=yRight=yLeftLast=yRightLast=-1.;
		yLLast=aLeft;
		yRLast=aRight;
		for(i=1;i<=edges[3]->intervals;i++)
		{	yLeft+=yLLast;
			yLLast*=rLeft;
			yRight+=yRLast;
			yRLast*=rRight;
			
			// Do mid side nodes on right edges of elements
			if(edges[0]->intervals>1)
			{	yLeftMid=(yLeftLast+yLeft)/2.;
				yRightMid=(yRightLast+yRight)/2.;
				botFraction=(1.-(yLeftMid+yRightMid)/2.)/2.;
				ratio=botFraction*ratioBot+(1-botFraction)*ratioTop;
				MeshLine((double)-1.,yLeftMid,(double)1.,yRightMid,ratio,edges[0]->intervals,FALSE);
			}
			
			// Do mid side nodes to tops of elements
			if(i!=edges[3]->intervals)
			{	botFraction=(1.-(yLeft+yRight)/2.)/2.;
				ratio=botFraction*ratioBot+(1-botFraction)*ratioTop;
				MeshLine((double)-1.,yLeft,(double)1.,yRight,ratio,edges[0]->intervals,TRUE);
			}
			
			// Save current point
			yLeftLast=yLeft;
			yRightLast=yRight;
		}
	}
	
	/* Mesh the area or get nodes in each element
	*/
	int row,rows=edges[1]->intervals;
	int col,cols=edges[0]->intervals;
	
	/* Calculate element numbers along surronding paths -
		First element means first one on boundary */
	int elemNum=theElems->numObjects;
	if(theElems->ElementSides()==3)
	{	edges[0]->firstElem=elemNum+1;
		edges[0]->elemIncrement=2;
		if(theElems->FlipTriangles())
			edges[1]->firstElem=elemNum+2*cols;
		else
			edges[1]->firstElem=elemNum+2*cols-1;
		edges[1]->elemIncrement=2*cols;
		edges[2]->firstElem=elemNum+2*rows*cols;
		edges[2]->elemIncrement=-2;
		if(theElems->FlipTriangles())
			edges[3]->firstElem=elemNum+2*(rows-1)*cols+1;
		else
			edges[3]->firstElem=elemNum+2*(rows-1)*cols+2;
		edges[3]->elemIncrement=-2*cols;
	}
	else if(theElems->ElementSides()==4)
	{	edges[0]->firstElem=elemNum+1;
		edges[0]->elemIncrement=1;
		edges[1]->firstElem=elemNum+cols;
		edges[1]->elemIncrement=cols;
		edges[2]->firstElem=elemNum+rows*cols;
		edges[2]->elemIncrement=-1;
		edges[3]->firstElem=elemNum+(rows-1)*cols+1;
		edges[3]->elemIncrement=-cols;
	}
	
	// Calculate the elements
	for(row=1;row<=rows;row++)
	{	for(col=1;col<=cols;col++)
		{	/* Assume all nodes are interior to area and get
				the nodes - wrong ones will be corrected latter */
			eNode[3]=firstInterior+(row-1)*(cols-1)+(col-1);
			eNode[4]=eNode[3]-1;
			eNode[1]=eNode[4]-(cols-1);
			eNode[2]=eNode[1]+1;
			if(theElems->HasMidsideNodes())
			{	eNode[6]=firstInteriorMidside+(row-1)*(2*cols-1)+(col-1);
				eNode[7]=eNode[6]+cols-1;
				eNode[8]=eNode[6]-1;
				eNode[5]=eNode[6]-cols;
			}
				
			// Correct nodes that are actually on an edge for first row
			if(row==1)
			{	// First assume rows and cols>1
				if(col==1)
				{	eNode[1]=(edges[0]->FirstKeypoint())->node;
					eNode[2]=edges[0]->firstMainNode;
					eNode[4]=edges[3]->firstMainNode+edges[3]->nodeIncrement*(rows-2);
					if(theElems->HasMidsideNodes())
					{	eNode[5]=edges[0]->firstMidsideNode;
						eNode[8]=edges[3]->firstMidsideNode+edges[3]->nodeIncrement*(rows-1);
					}
				}
				else if(col==cols)
				{	eNode[1]=edges[0]->firstMainNode+edges[0]->nodeIncrement*(cols-2);
					eNode[2]=(edges[0]->LastKeypoint())->node;
					eNode[3]=edges[1]->firstMainNode;
					if(theElems->HasMidsideNodes())
					{	eNode[5]=edges[0]->firstMidsideNode+edges[0]->nodeIncrement*(cols-1);
						eNode[6]=edges[1]->firstMidsideNode;
					}
				}
				else
				{	eNode[1]=edges[0]->firstMainNode+edges[0]->nodeIncrement*(col-2);
					eNode[2]=eNode[1]+edges[0]->nodeIncrement;
					if(theElems->HasMidsideNodes())
						eNode[5]=edges[0]->firstMidsideNode+edges[0]->nodeIncrement*(col-1);
				}
				
				/* Final correction for rows or cols equal to 1
					(Note: both will not be 1 (trapped earlier)) */
				if(rows==1)
				{	if(col==1)	// Note: cols won't be 1
					{	eNode[3]=edges[2]->firstMainNode+edges[2]->nodeIncrement*(cols-2);
						eNode[4]=(edges[3]->FirstKeypoint())->node;
						if(theElems->HasMidsideNodes())
							eNode[7]=edges[2]->firstMidsideNode+edges[2]->nodeIncrement*(cols-1);
					}
					else if(col==cols)
					{	eNode[3]=(edges[2]->FirstKeypoint())->node;
						eNode[4]=edges[2]->firstMainNode;
						if(theElems->HasMidsideNodes())
							eNode[7]=edges[2]->firstMidsideNode;
					}
					else
					{	eNode[3]=edges[2]->firstMainNode+edges[2]->nodeIncrement*(cols-col-1);
						eNode[4]=eNode[3]+edges[2]->nodeIncrement;
						if(theElems->HasMidsideNodes())
							eNode[7]=edges[2]->firstMidsideNode+edges[2]->nodeIncrement*(cols-col);
					}
				}
				else if(cols==1)	// Note rows can not also be 1
				{	eNode[2]=(edges[1]->FirstKeypoint())->node;
					eNode[3]=edges[1]->firstMainNode;
					if(theElems->HasMidsideNodes())
						eNode[6]=edges[1]->firstMidsideNode;
				}
			}
			
			// Correct nodes that are actually on an edge for last row
			else if(row==rows)
			{	if(col==1)
				{	eNode[1]=edges[3]->firstMainNode;
					eNode[3]=edges[2]->firstMainNode+edges[2]->nodeIncrement*(cols-2);
					eNode[4]=(edges[2]->LastKeypoint())->node;
					if(theElems->HasMidsideNodes())
					{	eNode[7]=edges[2]->firstMidsideNode+edges[2]->nodeIncrement*(cols-1);
						eNode[8]=edges[3]->firstMidsideNode;
					}
				}
				else if(col==cols)
				{	eNode[2]=edges[1]->firstMainNode+edges[1]->nodeIncrement*(rows-2);
					eNode[3]=(edges[1]->LastKeypoint())->node;
					eNode[4]=edges[2]->firstMainNode;
					if(theElems->HasMidsideNodes())
					{	eNode[6]=edges[1]->firstMidsideNode+edges[1]->nodeIncrement*(rows-1);
						eNode[7]=edges[2]->firstMidsideNode;
					}
				}
				else
				{	eNode[3]=edges[2]->firstMainNode+edges[2]->nodeIncrement*(cols-col-1);
					eNode[4]=eNode[3]+edges[2]->nodeIncrement;
					if(theElems->HasMidsideNodes())
						eNode[7]=edges[2]->firstMidsideNode+edges[2]->nodeIncrement*(cols-col);
				}
				
				/* Final correction cols equal to 1
					(Note: rows won't be 1 - it will come through in
						first in if(row==1) section */
				if(cols==1)
				{	eNode[3]=(edges[2]->FirstKeypoint())->node;
					eNode[2]=edges[1]->firstMainNode+edges[1]->nodeIncrement*(rows-2);
					if(theElems->HasMidsideNodes())
						eNode[6]=edges[1]->firstMidsideNode+edges[1]->nodeIncrement*(rows-1);
				}
			}
			
			// Correct nodes that are actually on an edge for interior rows
			else
			{	if(col==1)
				{	eNode[4]=edges[3]->firstMainNode+edges[3]->nodeIncrement*(rows-row-1);
					eNode[1]=eNode[4]+edges[3]->nodeIncrement;
					if(theElems->HasMidsideNodes())
						eNode[8]=edges[3]->firstMidsideNode+edges[3]->nodeIncrement*(rows-row);
				}
				
				if(col==cols)
				{	eNode[2]=edges[1]->firstMainNode+edges[1]->nodeIncrement*(row-2);
					eNode[3]=eNode[2]+edges[1]->nodeIncrement;
					if(theElems->HasMidsideNodes())
						eNode[6]=edges[1]->firstMidsideNode+edges[1]->nodeIncrement*(row-1);
				}
			}
			
			// Special case for 1 element area
			if(rows==1 && cols==1)
			{	eNode[1]=(edges[0]->FirstKeypoint())->node;
				eNode[2]=(edges[1]->FirstKeypoint())->node;
				eNode[3]=(edges[2]->FirstKeypoint())->node;
				eNode[4]=(edges[3]->FirstKeypoint())->node;
				if(theElems->HasMidsideNodes())
				{	eNode[5]=edges[0]->firstMidsideNode;
					eNode[6]=edges[1]->firstMidsideNode;
					eNode[7]=edges[2]->firstMidsideNode;
					eNode[8]=edges[3]->firstMidsideNode;
				}
			}
			
			// calculate angle
			if(angleExpr!=NULL)
			{	int imax= theElems->HasMidsideNodes() ? 4 : 8 ;
				Vector midPt;
				theNodes->MidPoint(&eNode[1],imax,&midPt);
				angle=FunctionValue(1,midPt.x,midPt.y,0.,0.,0.,0.);
			}
			
			if(!theElems->MeshElement(eNode,mat,angle,thick))
				return "Unable to create elements in the meshing area";
			
		}
	}

	/* adjust path faces for some elements */
	if(theElems->ElementSides()==3)
	{	if(!theElems->FlipTriangles())
		{	if(edges[2]->face>0) edges[2]->face=1;
			if(edges[3]->face>0) edges[3]->face=2;
		}
		else
		{	if(edges[3]->face>0) edges[3]->face=3;
		}
	}
	
	// all done
	return NULL;
}
コード例 #14
0
void RCamera::SetViewport() {
  switch (m_playerId) {
  case 0:
    switch (m_numPlayers) {
    case 1:
      glViewport(0,0,(int)m_width,(int)m_height);
      glScissor(0,0,(int)m_width,(int)m_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(GetFovy(),GetRatio(),GetNearDist(),GetFarDist());
      glMatrixMode(GL_MODELVIEW);
      break;
    case 2:
    case 3:
    case 4:
      glViewport(0,(int)m_height,(int)m_width,(int)m_height);
      glScissor(0,(int)m_height,(int)m_width,(int)m_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(GetFovy(),GetRatio(),GetNearDist(),GetFarDist());
      glMatrixMode(GL_MODELVIEW);
      break;
    default:
      cerr << "RCamera::SetViewport -- Bad m_numPlayers" << endl;
      exit(1);
    }
    break;
  case 1:
    switch (m_numPlayers) {
    case 1:
      cerr << "RCamera::SetViewport -- "
	   << "Attempting to set viewport for a player" 
	   << " that shouldn't exit" << endl;
      exit(1);
    case 2:
      glViewport(0,0,(int)m_width,(int)m_height);
      glScissor(0,0,(int)m_width,(int)m_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(GetFovy(),GetRatio(),GetNearDist(),GetFarDist());
      glMatrixMode(GL_MODELVIEW);
      break;
    case 3:
    case 4:
      glViewport((int)m_width,(int)m_height,(int)m_width,(int)m_height);
      glScissor((int)m_width,(int)m_height,(int)m_width,(int)m_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(GetFovy(),GetRatio(),GetNearDist(),GetFarDist());
      glMatrixMode(GL_MODELVIEW);
      break;
    default:
      cerr << "RCamera::SetViewport -- Bad m_numPlayers" << endl;
      exit(1);      
    }
    break;
  case 2:
    switch (m_numPlayers) {
    case 1:
    case 2:
      cerr << "RCamera::SetViewport -- "
	   << "Attempting to set viewport for a player" 
	   << " that shouldn't exit" << endl;
      exit(1);
    case 3:
    case 4:
      glViewport(0,0,(int)m_width,(int)m_height);
      glScissor(0,0,(int)m_width,(int)m_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(GetFovy(),GetRatio(),GetNearDist(),GetFarDist());
      glMatrixMode(GL_MODELVIEW);
      break;
    default:
      cerr << "RCamera::SetViewport -- Bad m_numPlayers" << endl;
      exit(1);      
    }    
    break;
  case 3:
    switch (m_numPlayers) {
    case 1:
    case 2:
    case 3:
      cerr << "RCamera::SetViewport -- "
	   << "Attempting to set viewport for a player" 
	   << " that shouldn't exit" << endl;
      exit(1);
    case 4:
      glViewport((int)m_width,0,(int)m_width,(int)m_height);
      glScissor((int)m_width,0,(int)m_width,(int)m_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(GetFovy(),GetRatio(),GetNearDist(),GetFarDist());
      glMatrixMode(GL_MODELVIEW);
      break;
    default:
      cerr << "RCamera::SetViewport -- Bad m_numPlayers" << endl;
      exit(1);      
    }    
    break;
  default:
    cerr << "RCamera::SetViewport() -- Bad player Id" << endl;
    exit(1);
  }
}