void CorrespondenceEvaluate::generateInbetween(double t)
{
	auto scheduler = QSharedPointer<Scheduler>(new Scheduler);
	auto blender = QSharedPointer<TopoBlender>(new TopoBlender(GraphCorr, scheduler.data()));
	auto synthManager = QSharedPointer<SynthesisManager>(new SynthesisManager(GraphCorr, scheduler.data(), blender.data(), 1000));
	synthManager->genSynData();
	scheduler->timeStep = 1.0 / 100.0;
	scheduler->defaultSchedule();
	scheduler->executeAll();
	auto blendedModel = scheduler->allGraphs[t * (scheduler->allGraphs.size() - 1)];
	synthManager->renderGraph(*blendedModel, "test", false, 5);
}
ExteriorLights::ExteriorLights(const ExteriorLightsDefinition& definition,
                               bool useControlOptionAstronomicalClock)
  : ModelObject(ExteriorLights::iddObjectType(),definition.model())
{
  OS_ASSERT(getImpl<detail::ExteriorLights_Impl>());

  bool ok = true;

  ok = setExteriorLightsDefinition(definition);
  OS_ASSERT(ok);

  ScheduleConstant defaultSchedule(model());
  defaultSchedule.setValue(1.0);
  defaultSchedule.setName(name().get() + " Always On Schedule");
  ok = setSchedule(defaultSchedule);
  OS_ASSERT(ok);

  if (useControlOptionAstronomicalClock) {
    ok = setControlOption("AstronomicalClock");
    OS_ASSERT(ok);
  }
}
Exemple #3
0
void AutoBlend::doBlend()
{
	auto selected = gallery->getSelected();
	if (selected.size() < 2) return;

    for(auto t : results->items) t->deleteLater();
    results->items.clear();

    ((GraphicsScene*)scene())->showPopup("Please wait..");

    for(int shapeI = 0; shapeI < selected.size(); shapeI++)
    {
        for(int shapeJ = shapeI + 1; shapeJ < selected.size(); shapeJ++)
        {
            //auto sourceName = selected.front()->data["targetName"].toString();
            //auto targetName = selected.back()->data["targetName"].toString();

            auto sourceName = selected[shapeI]->data.value("targetName").toString();
            auto targetName = selected[shapeJ]->data.value("targetName").toString();

            auto cacheSource = document->cacheModel(sourceName);
            auto cacheTarget = document->cacheModel(targetName);

            if(cacheSource == nullptr || cacheTarget == nullptr) continue;

            auto source = QSharedPointer<Structure::Graph>(cacheSource->cloneAsShapeGraph());
			auto target = QSharedPointer<Structure::Graph>(cacheTarget->cloneAsShapeGraph());

			auto gcorr = QSharedPointer<GraphCorresponder>(new GraphCorresponder(source.data(), target.data()));

			// Apply computed correspondence
            //if (false) // enable/disable auto correspondence
			{
                QVector<QPair<QString, QString> > all_pairs;

                for(auto n : source->nodes)
                {
                    if (!document->datasetCorr[sourceName][n->id][targetName].empty())
                    {
                        for(auto nj : document->datasetCorr[sourceName][n->id][targetName])
                        {
                            all_pairs << qMakePair(n->id, nj);
                        }
                    }
                }

                ResolveCorrespondence(source.data(), target.data(), all_pairs, gcorr.data());
			}

            gcorr->computeCorrespondences();

            // Schedule blending sequence
            auto scheduler = QSharedPointer<Scheduler>(new Scheduler);
            auto blender = QSharedPointer<TopoBlender>(new TopoBlender(gcorr.data(), scheduler.data()));

            // Sample geometries
            int numSamples = 100;
            int reconLevel = 4;

            int LOD = widget->levelDetails->currentIndex();
            switch (LOD){
                case 0: numSamples = 100; reconLevel = 4; break;
                case 1: numSamples = 1000; reconLevel = 5; break;
                case 2: numSamples = 10000; reconLevel = 7; break;
            }

            /// Visualize schedule:
            if (false)
            {
                blender->parentWidget = new QMainWindow();
                blender->parentWidget->show();
                blender->setupUI();

                QStringList corr;
                for(auto n : scheduler->activeGraph->nodes){
                    corr << QString("%1-%2").arg(n->id, n->property["correspond"].toString());
                }

                QMessageBox::information(blender->parentWidget, "Correspondence", corr.join("\n"));
            }

            auto synthManager = QSharedPointer<SynthesisManager>(new SynthesisManager(gcorr.data(), scheduler.data(), blender.data(), numSamples));
            synthManager->genSynData();

            // Compute blending
            scheduler->timeStep = 1.0 / 100.0;
            scheduler->defaultSchedule();
            scheduler->executeAll();

            int numResults = widget->count->value();

            for (int i = 0; i < numResults; i++)
            {
                double a = ((double(i) / (numResults - 1)) * 0.9) + 0.05;
                auto blendedModel = scheduler->allGraphs[a * (scheduler->allGraphs.size() - 1)];

                synthManager->renderGraph(*blendedModel, "", false, reconLevel );

                auto t = results->addTextItem("");
                t->setCamera(cameraPos, cameraMatrix);

                QVariantMap data;
                data["name"] = QString("%1_%2").arg(sourceName).arg(targetName);
                t->setData(data);

                // Add parts of target shape
                for (auto n : blendedModel->nodes){
                    t->addAuxMesh(toBasicMesh(blendedModel->getMesh(n->id), n->vis_property["color"].value<QColor>()));
                }
            }
        }
    }

    ((GraphicsScene*)scene())->hidePopup();
}
void PathEvaluator::test_filtering()
{
	/// Export results:
	QString sessionName = QString("session_%1").arg(QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss"));
	QString path = "results/" + sessionName;
	QDir d("");	d.mkpath( path ); d.mkpath( path + "/images" );

	int timeLimit = 5000; // ms
	int numInBetweens = 8;
	int numSamplesPerPath = numInBetweens * 3;

	/// Get number of paths to evaluate:
	int numPaths = 0;
	{
		Scheduler defaultSchedule( *b->m_scheduler );

		// Find time it takes for a single path
		QElapsedTimer timer; timer.start();
		{
			defaultSchedule.setSchedule( b->m_scheduler->getSchedule() ); // default
			defaultSchedule.timeStep = 1.0 / numSamplesPerPath;
			defaultSchedule.executeAll();
		}

		// FIXME
		// numPaths = qMax(1.0, double(timeLimit) / timer.elapsed() * omp_get_num_threads());
		numPaths = qMax(1.0, double(timeLimit) / timer.elapsed() * 4);

		// Export source and target images
		QColor inputColor(255,255,255);
		b->renderer->quickRender(defaultSchedule.allGraphs.front(), inputColor).save(path + "/images/source.png");
		b->renderer->quickRender(defaultSchedule.allGraphs.back(), inputColor).save(path + "/images/target.png");
	}

	// Force number of paths
	numPaths = 30;

	// Do this once for input graphs
	QVector<Structure::Graph*> inputGraphs;
	inputGraphs << b->s->inputGraphs[0]->g << b->s->inputGraphs[1]->g;

	ScorerManager r_manager(b->m_gcorr, b->m_scheduler.data(), inputGraphs);
	r_manager.parseConstraintPair();
	r_manager.parseConstraintGroup();
	r_manager.parseGlobalReflectionSymm();

	QVector<ScorerManager::PathScore> ps( numPaths );
	MatrixXd allRanges( numPaths, 3 * 4 );

	QVector<ScheduleType> allPaths = b->m_scheduler->manyRandomSchedules( numPaths );

	QElapsedTimer evalTimer; evalTimer.start();

	//#pragma omp parallel for
	for(int i = 0; i < allPaths.size(); i++)
	{
		// Setup schedule
		Scheduler s( *b->m_scheduler );
		s.setSchedule( allPaths[i] );
		s.timeStep = 1.0 / numSamplesPerPath;

		// Execute blend
		s.executeAll();

		// Compute its score
		ps[i] = r_manager.pathScore( s.allGraphs );

		QVector<QColor> colors;
		colors.push_back(QColor(255,0,0));
		colors.push_back(QColor(0,255,0));
		colors.push_back(QColor(0,0,255));

		// Range of values
		MatrixXd ranges = ps[i].computeRange();

		allRanges.row(i) = VectorXd::Map(ranges.data(), ranges.rows()*ranges.cols());

		//#pragma omp critical
		{
			QImage img(QSize(600,130), QImage::Format_ARGB32);
			img.fill(qRgba(0,0,0,0));

			QPainter painter(&img);
			painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

			// Text option
			QFont font("Monospace",8);
			font.setStyleHint(QFont::TypeWriter);
			painter.setFont(font);

			QVector<Structure::Graph*> inBetweens = s.topoVaryingInBetweens( numInBetweens );

			QVector< QVector<double> > scores(numInBetweens);

			int imgWidth = 0;

			for(int k = 0; k < numInBetweens; k++)
			{
				inBetweens[k]->moveCenterTo( AlphaBlend(inBetweens[k]->property["t"].toDouble(), 
					inBetweens[k]->property["sourceGraphCenter"].value<Vector3>(), 
					inBetweens[k]->property["targetGraphCenter"].value<Vector3>()), true);

				// Draw images
				QImage inBetween = b->renderer->quickRender(inBetweens[k], Qt::white);
				imgWidth = inBetween.width();

				// Rendered shape
				int newWidth = inBetween.width() * 0.5;
				int startX = k * newWidth;
				painter.drawImage(startX, 0, inBetween);

				// Store scores
				int idx = inBetweens[k]->property["graphIndex"].toInt();
				QVector<double> vals;
				vals << ps[i].connectivity[idx] << ps[i].localSymmetry[idx] << ps[i].globalSymmetry[idx];

				scores[k] = vals;
			}
			
			// Draw score lines
			for(int u = 0; u < scores.front().size(); u++)
			{
				// Graph
				QPainterPath poly;
				int padding = 0;

				QColor clr = colors[u];
				painter.setPen(QPen(clr, 1));

				// Render path
				for(int k = 0; k < numInBetweens; k++)
				{
					// Score graph
					//double minVal = ranges(u,0);
					//double range = ranges(u,2);

					//double val = (scores[k][u] - minVal) / range;
					double val = scores[k][u];

					// Graph line
					int newWidth = imgWidth * 0.5;
					int startX = k * newWidth;
					int x = startX + newWidth;
					int y = padding + (img.height() - (img.height() * val));

					if(k == 0)
						poly.moveTo(x, y);
					else
						poly.lineTo(x, y);

					// Dots
					painter.drawEllipse(QPoint(x,y), 2, 2);
				}

				painter.setBrush(Qt::NoBrush);
				painter.drawPath(poly);
			}

			// Draw ranges
			QStringList vals;
			for(int r = 0; r < 3; r++){
				QStringList curVals;
				for(int c = 0; c < 4; c++)
					curVals << QString::number(ranges(r,c),'f',2);
				vals << curVals.join("  ");
			}

			if( false )
			{
				painter.setPen(Qt::white);
				painter.drawText(11, img.height() - 9, vals.join("   #   "));

				painter.setPen(Qt::black);
				painter.drawText(10, img.height() - 10, vals.join("   #   "));
			}

			img.save( path + QString("/images/%1.png").arg(i) );
		}
	}

	// Get global average for the measures
	Vector3d globalAvg (allRanges.col(9).mean(), allRanges.col(10).mean(), allRanges.col(11).mean());

	// Sort based on score
	QMap<int,double> scoreMap;
	for(int i = 0; i < numPaths; i++) scoreMap[i] = ps[i].score();

	QVector<int> sortedIndices;
	typedef QPair<double,int> ValIdx;
	foreach(ValIdx d, sortQMapByValue( scoreMap )){
		sortedIndices.push_back( d.second );
	}