Example #1
0
/**
 * @function OnToolScreenshot
 * @brief Save a screenshot of the current GUI (Viewer and whole frame)
 * @date 2011-10-13
 */
void GRIPFrame::OnToolScreenshot(wxCommandEvent& WXUNUSED(event)) {
    wxYield();

    int w,h;
    wxClientDC dc(viewer);
    dc.GetSize(&w, &h);

    unsigned char* imageData = (unsigned char*) malloc(w * h * 3);
    glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, imageData);
    wxImage img_ud(w,h,imageData);
    wxImage img = img_ud.Mirror(false);
    img.SaveFile(wxT("ScreenGL.png"), wxBITMAP_TYPE_PNG ); // Save GL image
    wxBitmap glbit(img); // Create a bitmap from GL image

    int w2,h2;
    wxClientDC dc2(this);
    dc2.GetSize(&w2, &h2);
    wxBitmap bit;
    bit.Create(w2,h2);
    wxMemoryDC mem(bit);
    mem.Blit(0,0,w2,h2,&dc2,0,0); // Blit the window
    mem.DrawBitmap(glbit,2,2);    // Draw the GL image
    bit.SaveFile(wxT("Screen.png"), wxBITMAP_TYPE_PNG );

    SetStatusText(wxT("Screenshots saved in: Screen.png and ScreenGL.png"));
}
Example #2
0
    GraphicsBenchmarkFrame()
        : wxFrame(NULL, wxID_ANY, "wxWidgets Graphics Benchmark")
    {
        Connect(wxEVT_PAINT,
                wxPaintEventHandler(GraphicsBenchmarkFrame::OnPaint));

        Show();
        SetClientSize(opts.width, opts.height);
        wxClientDC dc(this);
        BenchmarkLines("client", dc);

        wxBitmap bmp(opts.width, opts.height);
        wxMemoryDC dc2(bmp);
        BenchmarkLines("memory", dc2);
    }
Example #3
0
void database_testDatacell()
{
	std::string data("Text");
	DBAbstraction::DataCell dc1(data.c_str());
	DBAbstraction::DataCell dc2("");

	dc2=dc1;
	ASSERT_EQUAL(data,dc2.getString());
	ASSERT_THROWS(dc2.getInt(), dbexception );
	ASSERT_THROWS(dc2.getBool(), dbexception );

	DBAbstraction::DataCell dci(1);
	ASSERT_EQUAL(1,dci.getInt());
	ASSERT_THROWS(dci.getString(), dbexception );

}
Example #4
0
bool BF3PointCircle::getCircle(BFCoordinate<int> c1, BFCoordinate<int> c2, BFCoordinate<int> c3, BFCircle& circle) {
	BFCoordinate<double> center;
	bool bCenter = BF3PointCircle::getCenter(c1,c2,c3,center);

	if(bCenter == false)
		return false;

	circle.setX0(center.getX());
	circle.setY0(center.getY());

	BFCoordinate<double> dc1(static_cast<double>(c1.getX()), static_cast<double>(c1.getY()));
	BFCoordinate<double> dc2(static_cast<double>(c2.getX()), static_cast<double>(c2.getY()));
	BFCoordinate<double> dc3(static_cast<double>(c3.getX()), static_cast<double>(c3.getY()));

	double r1 = BFCoordinate<double>::distance(center, dc1);
	double r2 = BFCoordinate<double>::distance(center, dc2);
	double r3 = BFCoordinate<double>::distance(center ,dc3);

	double r = (r1+r2+r3)/3.0;

	circle.setR(r);

	return true;
}
Example #5
0
    void IsdaCdsEngine::calculate() const {

        QL_REQUIRE(numericalFix_ == None || numericalFix_ == Taylor,
                   "numerical fix must be None or Taylor");
        QL_REQUIRE(accrualBias_ == HalfDayBias || accrualBias_ == NoBias,
                   "accrual bias must be HalfDayBias or NoBias");
        QL_REQUIRE(forwardsInCouponPeriod_ == Flat ||
                       forwardsInCouponPeriod_ == Piecewise,
                   "forwards in coupon period must be Flat or Piecewise");

        // it would be possible to handle the cases which are excluded below,
        // but the ISDA engine is not explicitly specified to handle them,
        // so we just forbid them too

        Actual365Fixed dc;
        Actual360 dc1;
        Actual360 dc2(true);

        Date evalDate = Settings::instance().evaluationDate();

        // check if given curves are ISDA compatible
        // (the interpolation is checked below)

        QL_REQUIRE(!discountCurve_.empty(), "no discount term structure set");
        QL_REQUIRE(!probability_.empty(), "no probability term structure set");
        QL_REQUIRE(discountCurve_->dayCounter() == dc,
                   "yield term structure day counter ("
                       << discountCurve_->dayCounter()
                       << ") should be Act/365(Fixed)");
        QL_REQUIRE(probability_->dayCounter() == dc,
                   "probability term structure day counter ("
                       << probability_->dayCounter() << ") should be "
                       << "Act/365(Fixed)");
        QL_REQUIRE(discountCurve_->referenceDate() == evalDate,
                   "yield term structure reference date ("
                       << discountCurve_->referenceDate()
                       << " should be evaluation date (" << evalDate << ")");
        QL_REQUIRE(probability_->referenceDate() == evalDate,
                   "probability term structure reference date ("
                       << probability_->referenceDate()
                       << " should be evaluation date (" << evalDate << ")");
        QL_REQUIRE(arguments_.settlesAccrual,
                   "ISDA engine not compatible with non accrual paying CDS");
        QL_REQUIRE(arguments_.paysAtDefaultTime,
                   "ISDA engine not compatible with end period payment");
        QL_REQUIRE(boost::dynamic_pointer_cast<FaceValueClaim>(
                       arguments_.claim) != NULL,
                   "ISDA engine not compatible with non face value claim");

        Date maturity = arguments_.maturity;
        Date effectiveProtectionStart =
            std::max<Date>(arguments_.protectionStart, evalDate + 1);

        // collect nodes from both curves and sort them
        std::vector<Date> yDates, cDates;

        if(boost::shared_ptr<InterpolatedDiscountCurve<LogLinear> > castY1 =
            boost::dynamic_pointer_cast<
                InterpolatedDiscountCurve<LogLinear> >(*discountCurve_)) {
            yDates = castY1->dates();
        } else if(boost::shared_ptr<InterpolatedForwardCurve<BackwardFlat> >
        castY2 = boost::dynamic_pointer_cast<
            InterpolatedForwardCurve<BackwardFlat> >(*discountCurve_)) {
            yDates = castY2->dates();
        } else if(boost::shared_ptr<InterpolatedForwardCurve<ForwardFlat> >
        castY3 = boost::dynamic_pointer_cast<
            InterpolatedForwardCurve<ForwardFlat> >(*discountCurve_)) {
            yDates = castY3->dates();
        } else if(boost::shared_ptr<FlatForward> castY4 =
            boost::dynamic_pointer_cast<FlatForward>(*discountCurve_)) {
        } else {
            QL_FAIL("Yield curve must be flat forward interpolated");
        }

        if(boost::shared_ptr<InterpolatedSurvivalProbabilityCurve<LogLinear> >
        castC1 = boost::dynamic_pointer_cast<
            InterpolatedSurvivalProbabilityCurve<LogLinear> >(
            *probability_)) {
            cDates = castC1->dates();
        } else if(
        boost::shared_ptr<InterpolatedHazardRateCurve<BackwardFlat> > castC2 =
            boost::dynamic_pointer_cast<
            InterpolatedHazardRateCurve<BackwardFlat> >(*probability_)) {
            cDates = castC2->dates();
        } else if(
        boost::shared_ptr<FlatHazardRate> castC3 =
            boost::dynamic_pointer_cast<FlatHazardRate>(*probability_)) {
        } else{
            QL_FAIL("Credit curve must be flat forward interpolated");
        }

        std::vector<Date> nodes;
        std::set_union(yDates.begin(), yDates.end(), cDates.begin(), cDates.end(), std::back_inserter(nodes));


        if(nodes.empty()){
            nodes.push_back(maturity);
        }
        const Real nFix = (numericalFix_ == None ? 1E-50 : 0.0);

        // protection leg pricing (npv is always negative at this stage)
        Real protectionNpv = 0.0;

        Date d0 = effectiveProtectionStart-1;
        Real P0 = discountCurve_->discount(d0);
        Real Q0 = probability_->survivalProbability(d0);
        Date d1;
        std::vector<Date>::const_iterator it =
            std::upper_bound(nodes.begin(), nodes.end(), effectiveProtectionStart);

        for(;it != nodes.end(); ++it) {
            if(*it > maturity) {
                d1 = maturity;
                it = nodes.end() - 1; //early exit
            } else {
                d1 = *it;
            }
            Real P1 = discountCurve_->discount(d1);
            Real Q1 = probability_->survivalProbability(d1);

            Real fhat = std::log(P0) - std::log(P1);
            Real hhat = std::log(Q0) - std::log(Q1);
            Real fhphh = fhat + hhat;

            if (fhphh < 1E-4 && numericalFix_ == Taylor) {
                Real fhphhq = fhphh * fhphh;
                protectionNpv +=
                    P0 * Q0 * hhat * (1.0 - 0.5 * fhphh + 1.0 / 6.0 * fhphhq -
                                      1.0 / 24.0 * fhphhq * fhphh +
                                      1.0 / 120 * fhphhq * fhphhq);
            } else {
                protectionNpv += hhat / (fhphh + nFix) * (P0 * Q0 - P1 * Q1);
            }
            d0 = d1;
            P0 = P1;
            Q0 = Q1;
        }
        protectionNpv *= arguments_.claim->amount(
            Null<Date>(), arguments_.notional, recoveryRate_);

        results_.defaultLegNPV = protectionNpv;

        // premium leg pricing (npv is always positive at this stage)

        Real premiumNpv = 0.0, defaultAccrualNpv = 0.0;
        for (Size i = 0; i < arguments_.leg.size(); ++i) {
            boost::shared_ptr<FixedRateCoupon> coupon =
                boost::dynamic_pointer_cast<FixedRateCoupon>(arguments_.leg[i]);

            QL_REQUIRE(coupon->dayCounter() == dc ||
                           coupon->dayCounter() == dc1 ||
                           coupon->dayCounter() == dc2,
                       "ISDA engine requires a coupon day counter Act/365Fixed "
                           << "or Act/360 (" << coupon->dayCounter() << ")");

            // premium coupons
            if (!arguments_.leg[i]->hasOccurred(effectiveProtectionStart,
                                                includeSettlementDateFlows_)) {
                premiumNpv +=
                    coupon->amount() *
                    discountCurve_->discount(coupon->date()) *
                    probability_->survivalProbability(coupon->date()-1);
            }

            // default accruals

            if (!detail::simple_event(coupon->accrualEndDate())
                     .hasOccurred(effectiveProtectionStart, false)) {
                Date start = std::max<Date>(coupon->accrualStartDate(),
                                            effectiveProtectionStart)-1;
                Date end = coupon->date()-1;
                Real tstart =
                    discountCurve_->timeFromReference(coupon->accrualStartDate()-1) -
                    (accrualBias_ == HalfDayBias ? 1.0 / 730.0 : 0.0);
                std::vector<Date> localNodes;
                localNodes.push_back(start);
                //add intermediary nodes, if any
                if (forwardsInCouponPeriod_ == Piecewise) {
                    std::vector<Date>::const_iterator it0 =
                        std::upper_bound(nodes.begin(), nodes.end(), start);
                    std::vector<Date>::const_iterator it1 =
                        std::lower_bound(nodes.begin(), nodes.end(), end);
                    localNodes.insert(localNodes.end(), it0, it1);
                }
                localNodes.push_back(end);

                Real defaultAccrThisNode = 0.;
                std::vector<Date>::const_iterator node = localNodes.begin();
                Real t0 = discountCurve_->timeFromReference(*node);
                Real P0 = discountCurve_->discount(*node);
                Real Q0 = probability_->survivalProbability(*node);

                for (++node; node != localNodes.end(); ++node) {
                    Real t1 = discountCurve_->timeFromReference(*node);
                    Real P1 = discountCurve_->discount(*node);
                    Real Q1 = probability_->survivalProbability(*node);
                    Real fhat = std::log(P0) - std::log(P1);
                    Real hhat = std::log(Q0) - std::log(Q1);
                    Real fhphh = fhat + hhat;
                    if (fhphh < 1E-4 && numericalFix_ == Taylor) {
                        // see above, terms up to (f+h)^3 seem more than enough,
                        // what exactly is implemented in the standard isda C
                        // code ?
                        Real fhphhq = fhphh * fhphh;
                        defaultAccrThisNode +=
                            hhat * P0 * Q0 *
                            ((t0 - tstart) *
                                 (1.0 - 0.5 * fhphh + 1.0 / 6.0 * fhphhq -
                                  1.0 / 24.0 * fhphhq * fhphh) +
                             (t1 - t0) *
                                 (0.5 - 1.0 / 3.0 * fhphh + 1.0 / 8.0 * fhphhq -
                                  1.0 / 30.0 * fhphhq * fhphh));
                    } else {
                        defaultAccrThisNode +=
                            (hhat / (fhphh + nFix)) *
                            ((t1 - t0) * ((P0 * Q0 - P1 * Q1) / (fhphh + nFix) -
                                          P1 * Q1) +
                             (t0 - tstart) * (P0 * Q0 - P1 * Q1));
                    }

                    t0 = t1;
                    P0 = P1;
                    Q0 = Q1;
                }
                defaultAccrualNpv += defaultAccrThisNode * arguments_.notional *
                    coupon->rate() * 365. / 360.;
			}
        }


        results_.couponLegNPV = premiumNpv + defaultAccrualNpv;

        // upfront flow npv

        Real upfPVO1 = 0.0;
        results_.upfrontNPV = 0.0;
        if (!arguments_.upfrontPayment->hasOccurred(
                evalDate, includeSettlementDateFlows_)) {
            upfPVO1 =
                discountCurve_->discount(arguments_.upfrontPayment->date());
            if(arguments_.upfrontPayment->amount() != 0.) {
                results_.upfrontNPV = upfPVO1 * arguments_.upfrontPayment->amount();
            }
        }

        results_.accrualRebateNPV = 0.;
        if (arguments_.accrualRebate &&
            arguments_.accrualRebate->amount() != 0. &&
            !arguments_.accrualRebate->hasOccurred(
                evalDate, includeSettlementDateFlows_)) {
            results_.accrualRebateNPV =
                discountCurve_->discount(arguments_.accrualRebate->date()) *
                arguments_.accrualRebate->amount();
        }

        Real upfrontSign = Protection::Seller ? 1.0 : -1.0;

        if (arguments_.side == Protection::Seller) {
            results_.defaultLegNPV *= -1.0;
            results_.accrualRebateNPV *= -1.0;
        } else {
            results_.couponLegNPV *= -1.0;
            results_.upfrontNPV *= -1.0;
        }

        results_.value = results_.defaultLegNPV + results_.couponLegNPV +
                         results_.upfrontNPV + results_.accrualRebateNPV;

        results_.errorEstimate = Null<Real>();

        if (results_.couponLegNPV != 0.0) {
            results_.fairSpread =
                -results_.defaultLegNPV * arguments_.spread /
                (results_.couponLegNPV + results_.accrualRebateNPV);
        } else {
            results_.fairSpread = Null<Rate>();
        }

        Real upfrontSensitivity = upfPVO1 * arguments_.notional;
        if (upfrontSensitivity != 0.0) {
            results_.fairUpfront =
                -upfrontSign * (results_.defaultLegNPV + results_.couponLegNPV +
                                results_.accrualRebateNPV) /
                upfrontSensitivity;
        } else {
            results_.fairUpfront = Null<Rate>();
        }

        static const Rate basisPoint = 1.0e-4;

        if (arguments_.spread != 0.0) {
            results_.couponLegBPS =
                results_.couponLegNPV * basisPoint / arguments_.spread;
        } else {
            results_.couponLegBPS = Null<Rate>();
        }

        if (arguments_.upfront && *arguments_.upfront != 0.0) {
            results_.upfrontBPS =
                results_.upfrontNPV * basisPoint / (*arguments_.upfront);
        } else {
            results_.upfrontBPS = Null<Rate>();
        }
    }
Example #6
0
void CHistogramDlg::OnPaint()
{
	CDialog::OnPaint();
	
	// color definition
	COLORREF black = RGB(0, 0, 0);
	COLORREF gray;
	
	// Get max value of histogram
	int hmax = 0; 
	for(size_t i = 0; i < hist_value_.size(); i++ ) {
		if( hmax < hist_value_[i] ) {
			hmax = hist_value_[i];
		}
	}

	// drawing
	CPaintDC dc(&show_hist_); // device context for painting
	
	// select new pen and new brush
	CPen newPen(PS_SOLID, 1, black);
	CPen* pOldPen = dc.SelectObject(&newPen);

	CBrush newBrush(black);
	CBrush* pOldBrush = dc.SelectObject(&newBrush);

	// get client size
	CRect rect;
	show_hist_.GetClientRect(&rect);

	// draw border
	dc.MoveTo( rect.left, rect.top );
	dc.LineTo( rect.right, rect.top );

	dc.MoveTo( rect.right, rect.top );
	dc.LineTo( rect.right, rect.bottom );

	dc.MoveTo( rect.right, rect.bottom );
	dc.LineTo( rect.left, rect.bottom );

	dc.MoveTo( rect.left, rect.bottom );
	dc.LineTo( rect.left, rect.top );

	// draw histogram
	float width = rect.right - rect.left - 1;
	float height = rect.bottom - rect.top - 1;
	float xstart = 1;
	float top = height;
	float step = width / hist_value_.size();
	
	rect.bottom = height + 1;
	for(size_t i = 0; i < hist_value_.size() ; i++)
	{
		rect.left  = (long)xstart;
		rect.right = (long)(xstart + step);
		rect.top   = (long)(height + 1 - ((float)hist_value_[i] / hmax) * top);
		dc.FillRect( rect, &newBrush );
		xstart += step;
	}

	dc.SelectObject( pOldBrush );
	dc.SelectObject( pOldPen );
    
    // IDC_HISTOGRAM_GRAY
	CPaintDC dc2(&show_gray_); // device context for painting
	show_gray_.GetClientRect(&rect);

	// draw border
	dc2.MoveTo( rect.left, rect.top );
	dc2.LineTo( rect.right, rect.top );

	dc2.MoveTo( rect.right, rect.top );
	dc2.LineTo( rect.right, rect.bottom );

	dc2.MoveTo( rect.right, rect.bottom );
	dc2.LineTo( rect.left, rect.bottom );

	dc2.MoveTo( rect.left, rect.bottom );
	dc2.LineTo( rect.left, rect.top );

	width = rect.right - rect.left - 1;
	height = rect.bottom - rect.top - 1;
	xstart = 1;
	step = 1;
	
	rect.bottom = height + 1;
	rect.top    = 1;
	for(int i = 0; i < (int)width;  i++)
	{
		rect.left  = (long) xstart;
		rect.right = (long) (xstart + step);

		char component = (int)((float)i / width * 256.0);
		gray = RGB( component, component, component );

		CBrush  brush(gray);
		pOldBrush = dc2.SelectObject(&brush);
		
		dc2.FillRect( rect, &brush );
		xstart += step;

		dc2.SelectObject( pOldBrush );
	}
 }
void CSkinDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		//画边线
		CPaintDC dc2(this);
		CRect rect;
		GetClientRect(rect);

		//背景绘图
		dc2.SetBkMode(TRANSPARENT);
		CDC MemDC;
		MemDC.CreateCompatibleDC(&dc2);
		CBitmap Bitmap;
		BITMAP bmpinfo;
		Bitmap.LoadBitmap(IDB_BK1);
		Bitmap.GetObject(sizeof(bmpinfo),& bmpinfo);  //获取图片信息
		CBitmap *pOldBitmap = MemDC.SelectObject(&Bitmap);
		
		dc2.StretchBlt(-1, -1, rect.Width()+2, rect.Height()+2, &MemDC, 0, 0, bmpinfo.bmWidth, bmpinfo.bmHeight, SRCCOPY);  //拉伸位图
//		dc2.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDC, rect.left, rect.top, SRCCOPY);
		MemDC.SelectObject(pOldBitmap);
		MemDC.DeleteDC();

		//外边框
		CPen *oldpen = NULL;
		CPen newpen(PS_SOLID, 1, RGB(27, 147, 186));
		oldpen = dc2.SelectObject(&newpen);

		dc2.MoveTo(rect.left, CORNER_SIZE);
		dc2.LineTo(CORNER_SIZE, rect.top);
		dc2.LineTo(rect.right - CORNER_SIZE - 1, rect.top);
		dc2.LineTo(rect.right - 1, CORNER_SIZE);
		dc2.LineTo(rect.right - 1, rect.bottom - CORNER_SIZE - 1);
		dc2.LineTo(rect.right - CORNER_SIZE - 1, rect.bottom - 1);
		dc2.LineTo(CORNER_SIZE, rect.bottom - 1);
		dc2.LineTo(rect.left, rect.bottom - CORNER_SIZE - 1);
		dc2.LineTo(rect.left, CORNER_SIZE);

		//填充空缺处
		dc2.MoveTo(rect.left + 1, CORNER_SIZE);
		dc2.LineTo(CORNER_SIZE + 1, rect.top);

		dc2.MoveTo(rect.right - CORNER_SIZE - 1, rect.top + 1);
		dc2.LineTo(rect.right - 1, CORNER_SIZE + 1);

		dc2.MoveTo(rect.right - 2, rect.bottom - CORNER_SIZE - 1);
		dc2.LineTo(rect.right - CORNER_SIZE - 1, rect.bottom - 1);

		dc2.MoveTo(CORNER_SIZE, rect.bottom - 2);
		dc2.LineTo(rect.left, rect.bottom - CORNER_SIZE - 2);

		dc2.SelectObject(oldpen);

		//内边框
		CPen newpen2(PS_SOLID, 1, RGB(196, 234, 247));
		oldpen = dc2.SelectObject(&newpen2);

		dc2.MoveTo(rect.left + 1, CORNER_SIZE + 1);
		dc2.LineTo(CORNER_SIZE + 1, rect.top + 1);
		dc2.LineTo(rect.right - CORNER_SIZE - 2, rect.top + 1);
		dc2.LineTo(rect.right - 2, CORNER_SIZE + 1);
		dc2.LineTo(rect.right - 2, rect.bottom - CORNER_SIZE - 2);
		dc2.LineTo(rect.right - CORNER_SIZE - 2, rect.bottom - 2);
		dc2.LineTo(CORNER_SIZE + 1, rect.bottom - 2);
		dc2.LineTo(rect.left + 1, rect.bottom - CORNER_SIZE - 2);
		dc2.LineTo(rect.left + 1, CORNER_SIZE + 1);
		CDialog::OnPaint();
	}
}
Example #8
0
/**
 * @function OnToolMovie
 * @brief
 * @date 2011-10-13
 */
void GRIPFrame::OnToolMovie(wxCommandEvent& event){
    wxString dirname = wxDirSelector(wxT("Choose output directory for movie pictures:")); // , "", wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST

    if ( dirname.empty() ){ // filename
        std::cout << "No Directory Selected" << std::endl;
	return;
    }

    string path = string(dirname.mb_str());

    char *buf = new char[1000];

	//Create a new Viewer Window
	wxFrame *movieFrame = new wxFrame(NULL,wxID_ANY, wxT("MovieWindow"),wxPoint(0, 0), wxSize(renderW,renderH),wxDEFAULT_FRAME_STYLE & ~ (wxRESIZE_BORDER | wxMAXIMIZE_BOX));
	//#ifndef WIN32 // Weird hack to make wxWidgets work in Linux
	movieFrame->Show();
	//#endif

	int attrib[] = {WX_GL_DOUBLEBUFFER,WX_GL_RGBA,	WX_GL_DEPTH_SIZE, 16,0};
	Viewer *movieViewer = new Viewer(movieFrame, viewer, wxID_ANY, wxPoint(0, 0), wxSize(renderW, renderH), 0, _T("MovieWindow"), attrib);
	movieViewer->backColor = viewer->backColor;
	movieViewer->gridColor = viewer->gridColor;	

	//movieFrame.AddChild(
	#ifdef WIN32  // Weird hack to make wxWidgets work with VC++ debug
	movieViewer->MSWSetOldWndProc((WXFARPROC)DefWindowProc);
	#endif

	int w,h;

	movieViewer->Show(true);
    movieViewer->Freeze();
    wxClientDC dc2(movieViewer);
    dc2.GetSize(&w, &h);
    movieViewer->InitGL();
    movieViewer->Thaw();
	movieViewer->handleEvents = false;
	movieViewer->Show(true);

	movieViewer->camT = viewer->camT;
	movieViewer->camRotT = viewer->camRotT;
	movieViewer->camRadius = viewer->camRadius;
	movieViewer->worldV = viewer->worldV;

    double curTargetTime = 0.0;
    std::vector<GRIPTimeSlice>::iterator it = timeVector.begin();
    int framesWritten = 0;

    double framerate = 30.0;

    do {
        if (it == timeVector.end()) break; // call it done
        while((*it).time < curTargetTime) it++;

		// Issue 122 from DART
        //mWorld->setState((*it).state);
		Eigen::VectorXd newState = (*it).state;   
    	setState_Issue122( newState );

        movieViewer->DrawGLScene();
        wxYield();

        unsigned char* imageData = (unsigned char*) malloc(w * h * 3);
        glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, imageData);
        wxImage img_ud(w,h,imageData);
        wxImage img = img_ud.Mirror(false);

        sprintf(buf, "%s/%06d.png",path.c_str(), framesWritten);

        wxString fname = wxString(buf,wxConvUTF8);
        cout << "Saving frame at t = " << (*it).time << " (targeting " << curTargetTime << ") into " << buf << "" << endl;
        img.SaveFile(fname, wxBITMAP_TYPE_PNG);

        framesWritten++;

        curTargetTime += 1.0 / framerate;
    } while (curTargetTime < timeVector.back().time);


	delete movieViewer;
	delete movieFrame;
	viewer->InitGL();

    delete buf;
    event.Skip();
}