void PPL7FramePainter::paintEvent(QPaintEvent *)
{

	if (!img) return;
	QPainter painter(this);
	QPoint p(0,0);
	switch (smode) {
		case None:
		{
			QImage qi((uchar*)img->adr(),img->width(),img->height(), img->pitch(), QImage::Format_RGB32);
			painter.drawImage(p,qi);
			break;
		}
		case Fast:
		{
			int nw,nh;
			float ratio=(float)img->width()/(float)img->height();
			if (height()*ratio>width()) {
				nw=width();
				nh=(int)((float)nw/ratio);
			} else {
				nh=height();
				nw=(int)((float)nh*ratio);
			}
			p.setX((width()-nw)/2);
			p.setY((height()-nh)/2);


			QImage qi((uchar*)img->adr(),img->width(),img->height(), img->pitch(), QImage::Format_RGB32);
			QImage sc=qi.scaled(width(),height(),Qt::KeepAspectRatio,Qt::FastTransformation);
			painter.drawImage(p,sc);
			break;
		}
		case Smooth:
		{
			int nw,nh;
			float ratio=(float)img->width()/(float)img->height();
			if (height()*ratio>width()) {
				nw=width();
				nh=(int)((float)nw/ratio);
			} else {
				nh=height();
				nw=(int)((float)nh*ratio);
			}
			p.setX((width()-nw)/2);
			p.setY((height()-nh)/2);


			QImage qi((uchar*)img->adr(),img->width(),img->height(), img->pitch(), QImage::Format_RGB32);
			QImage sc=qi.scaled(width(),height(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
			painter.drawImage(p,sc);
			break;
		}

	}


}
Beispiel #2
0
void QuadInterptest::test_flat()
{
  dymaxion::QuadInterp qi(4, 2, 2, 2, 2);

  ASSERT_TRUE(qi.noCalc);
  ASSERT_EQUAL(qi.m_size, 4);
}
Beispiel #3
0
int main(int argc, char **argv) {
  #ifndef UNITY_BUILD
  Q_INIT_RESOURCE(stuff);
  Q_INIT_RESOURCE(stuff2);
  #endif
  QApplication app(argc, argv);
  MainWindow *win = new MainWindow();
  QImage qi(":/thing.png");
  if(qi.width() != 640) {
      return 1;
  }
  QImage qi2(":/thing2.png");
  if(qi2.width() != 640) {
      return 1;
  }
  win->setWindowTitle("Meson Qt5 build test");
  QLabel *label_stuff = win->findChild<QLabel *>("label_stuff");
  if(label_stuff == nullptr) {
      return 1;
  }
  int w = label_stuff->width();
  int h = label_stuff->height();
  label_stuff->setPixmap(QPixmap::fromImage(qi).scaled(w,h,Qt::KeepAspectRatio));
  QLabel *label_stuff2 = win->findChild<QLabel *>("label_stuff2");
  if(label_stuff2 == nullptr) {
      return 1;
  }
  w = label_stuff2->width();
  h = label_stuff2->height();
  label_stuff2->setPixmap(QPixmap::fromImage(qi2).scaled(w,h,Qt::KeepAspectRatio));
  win->show();
  return app.exec();
  return 0;
}
Beispiel #4
0
void QuadInterptest::test_calc()
{
  dymaxion::QuadInterp qi(4, 2, 4, 6, 8);

  ASSERT_TRUE(!qi.noCalc);
  ASSERT_EQUAL(qi.calc(2, 2), 5);
}
void RTUVCCamMainWindow::displayImageSlot(QByteArray image,
                                              int width, int height, QString timestamp)
{
    QImage qi((const uchar *)image.data(), width, height, QImage::Format_RGB888);
    QImage rgbImage = qi.rgbSwapped();
    displayPixmap(rgbImage, timestamp);
}
Beispiel #6
0
void QuadInterptest::test_QuadInterp()
{
  dymaxion::QuadInterp qi(4, 2, 4, 6, 8);

  ASSERT_TRUE(!qi.noCalc);
  ASSERT_EQUAL(qi.m_size, 4);
}
void can_insert_keyframe_visitor::operator()( const anim::float_curve_t *c)
{
	float val = c->evaluate( time_);
	val = c->relative_to_absolute( val);
	Imath::V2i qi( view_.world_to_screen( Imath::V2f( time_, val)));
	can_insert = view_.inside_pick_distance( p_, qi);
}
Beispiel #8
0
void QuadInterptest::test_calc_nocalc()
{
  dymaxion::QuadInterp qi(4, 2, 2, 2, 2);

  ASSERT_TRUE(qi.noCalc);
  ASSERT_EQUAL(qi.calc(2, 2), 2);
}
Beispiel #9
0
 Q_SLOT void sendImage() {
     QImage qi(img.image());
     qDebug() << "QImage buffer before" << name(qi.constScanLine(0));
     emit matSignal(img);
     emit imgSignal(img.image());
     qDebug() << "QImage buffer after" << name(qi.constScanLine(0));
     // Note: this is wrong since img is not allocated on the heap.
     //emit imgSignal(QImage(img.mat().data, img.mat().rows, img.mat().cols, QImage::Format_ARGB32, matDeleter, &img));
     emit imgSignal(QImage(img.mat().data, img.mat().rows, img.mat().cols, QImage::Format_ARGB32));
 }
Beispiel #10
0
bool Quotas::save() {
  QIntDictIterator<Quota> qi(q);

  while (qi.current()) {
    if (!qi.current()->save())
      return (FALSE);
    ++qi;
  }
  return (TRUE);
}
Beispiel #11
0
int main()
{
    int choice = -1;
    Queue q;

    while (true)
    {
        std::cout << "\nMENU\n\n"
                  << "Select an action:\n"
                  << "1) Add integer to queue\n"
                  << "2) Remove integer from queue\n"
                  << "3) Print queue contents\n"
                  << "4) Run queue debug tests\n"
                  << "5) Exit\n\n";

        choice = utilities::get_valid_int_in_range(1, 5);

        switch (choice)
        {
            case 1:
            {
                std::cout << "Add an integer to queue from "
                          << "0 through 1000: ";
                int val = utilities::get_valid_int_in_range(0, 1000);
                q.add_back(val);
                break;
            }
            case 2:
            {
                int val = q.remove_front();
                if (val == -1) 
                    std::cout << "Empty queue!\n";
                else
                    std::cout << "Removed " << val << " from queue.\n";
                break;
            }
            case 3:
            {
                QueueIter qi(q);
                qi.print_elements();
                break;
            }
            case 4:
            {
                test();
                break;
            }
            case 5:
            {
                return 0;
            }
        }

    }
}
Beispiel #12
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(UtilsTest, toTextureImage_withSinglePixelImage)
{
    QImage qi(1, 1, QImage::Format_ARGB32);
    qi.setPixel(0,0, qRgba(1, 2, 3, 4)); 

    cvf::TextureImage i;
    cvfqt::Utils::toTextureImage(qi, &i);
    ASSERT_EQ(1, i.width());
    ASSERT_EQ(1, i.height());
    EXPECT_EQ(cvf::Color4ub(1, 2, 3, 4), i.pixel(0,0));  
}
Beispiel #13
0
void quaterN::hermite0(const quater& a, const quater& b, int duration, const quater& c, const quater& d, float interval)
{
	quater qi(1,0,0,0);
	hermite(a,b,duration, qi, qi, interval);
	quaterN temp;
	temp.hermite(qi,qi,duration, c, d, interval);

	float totalTime=duration+1;
	for(int i=0; i<duration; i++)
	{
		row(i).slerp(row(i), temp.row(i), (float)(i+1)/totalTime );
	}
}
Beispiel #14
0
void IMG_linkrelout(Image_t *img, uaddr_t addr, const char *name, const char *segname) {
    assert(img != NULL);

    sqlq_t qi(img->db, "INSERT OR IGNORE INTO tab_label(name, type, module, segment) VALUES(@N, 0, NULL, "
        "(SELECT segid FROM tab_segment WHERE name=@B))");
    qi.bind_str(1, name);
    qi.bind_str(2, segname);
    qi.run();
    sqlq_t qu(img->db, "UPDATE tab_reloc SET label=(SELECT labid FROM tab_label WHERE name=@A) "
                       "WHERE address=@C");
    qu.bind_str(1, name);
    qu.bind_int(2, addr);
    qu.run();
}
Beispiel #15
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(UtilsTest, toTextureImage_premultipliedImageFormat)
{
    QImage qi(4, 3, QImage::Format_ARGB32_Premultiplied);
    qi.setPixel(0,0, qRgba( 0,10,50,100));   qi.setPixel(1,0, qRgba( 1,11,51,101));   qi.setPixel(2,0, qRgba( 2,12,52,102));   qi.setPixel(3,0, qRgba( 3,13,53,103));
    qi.setPixel(0,1, qRgba( 4,14,54,104));   qi.setPixel(1,1, qRgba( 5,15,55,105));   qi.setPixel(2,1, qRgba( 6,16,56,106));   qi.setPixel(3,1, qRgba( 7,17,57,107));
    qi.setPixel(0,2, qRgba( 8,18,58,108));   qi.setPixel(1,2, qRgba( 9,19,59,109));   qi.setPixel(2,2, qRgba(10,20,60,110));   qi.setPixel(3,2, qRgba(11,21,61,111));

    cvf::TextureImage i;
    cvfqt::Utils::toTextureImage(qi, &i);
    ASSERT_EQ(4, i.width());
    ASSERT_EQ(3, i.height());

    EXPECT_EQ(cvf::Color4ub( 0,10,50,100), i.pixel(0,2));  EXPECT_EQ(cvf::Color4ub( 1,11,51,101), i.pixel(1,2));  EXPECT_EQ(cvf::Color4ub( 2,12,52,102), i.pixel(2,2));  EXPECT_EQ(cvf::Color4ub( 3,13,53,103), i.pixel(3,2));
    EXPECT_EQ(cvf::Color4ub( 4,14,54,104), i.pixel(0,1));  EXPECT_EQ(cvf::Color4ub( 5,15,55,105), i.pixel(1,1));  EXPECT_EQ(cvf::Color4ub( 6,16,56,106), i.pixel(2,1));  EXPECT_EQ(cvf::Color4ub( 7,17,57,107), i.pixel(3,1));
    EXPECT_EQ(cvf::Color4ub( 8,18,58,108), i.pixel(0,0));  EXPECT_EQ(cvf::Color4ub( 9,19,59,109), i.pixel(1,0));  EXPECT_EQ(cvf::Color4ub(10,20,60,110), i.pixel(2,0));  EXPECT_EQ(cvf::Color4ub(11,21,61,111), i.pixel(3,0));
}
Beispiel #16
0
void SCRIBUS_API iconToGrayscale(QPixmap* pm)
{
	QImage qi(pm->toImage());
	int h=qi.height();
	int w=qi.width();
	QRgb c_rgb;
	for (int i=0;i<w;++i)
	{
		for (int j=0;j<h;++j)
		{
			c_rgb=qi.pixel(i,j);
			int k = qMin(qRound(0.3 * qRed(c_rgb) + 0.59 * qGreen(c_rgb) + 0.11 * qBlue(c_rgb)), 255);
			qi.setPixel(i, j, qRgba(k, k, k, qAlpha(c_rgb)));
		}
	}
	*pm=QPixmap::fromImage(qi);
}
Beispiel #17
0
Eigen::Matrix<T,4,1> rotate_to_plane(Eigen::Matrix<T,4,1> normP, 
				     Eigen::Matrix<T,4,1> norm, 
				     Eigen::Matrix<T,4,1> cen, 
				     Eigen::Matrix<T,4,1> vec){
  norm.normalize();
  normP.normalize();	
  Eigen::Matrix<T,4,1> xe = cross(norm,normP).normalize();
  T r1 = norm.mag();
  T rP = normP.mag();
  T o = acos(dot(normP,norm)/r1/rP) - M_PI;
  T o0 = acos(dot(normP,norm)/r1/rP);
  Eigen::Quaternion<T> qP(normP);
  Eigen::Quaternion<T> qi(norm);
  //	Eigen::Quaternion<T>  dq = (qP-qi).normalize();
  Eigen::Quaternion<T> dq(cos(o/2.), sin(o/2.)*xe[0], sin(o/2.)*xe[1], sin(o/2.)*xe[2]);		
  //	Eigen::Quaternion<T> dq = qP*qi.conj()*qP;
  Eigen::Matrix<T,4,1> c = dq.normalize().rotate(vec - cen);
  return c;
}
void pick_generic_node( node_t *n, const Imath::V2f& p, const composition_view_t& view, pick_result_t& result)
{
    result.node = 0;
    result.component = pick_result_t::no_pick;
    result.plug_num = -1;

    if( ( p.x < n->location().x) || (p.x > n->location().x + generic_node_width( n)))
        return;

    if( ( p.y < n->location().y - 6.0) || ( p.y > n->location().y + generic_node_height() + 5))
        return;

    result.node = n;
    result.component = pick_result_t::body_picked;

    Imath::V2f q( generic_output_location( n));

    Imath::V2i pi( view.world_to_screen( p));
    Imath::V2i qi( view.world_to_screen( q));

    if( ( pi - qi).length2() < 25)
    {
        result.component = pick_result_t::output_picked;
        result.plug_num = 0;
        return;
    }

    for( unsigned int i=0;i<n->num_inputs();++i)
    {
        q = generic_input_location( n, i);
        qi = view.world_to_screen( q);

        if( ( pi - qi).length2() < 25)
        {
            result.component = pick_result_t::input_picked;
            result.plug_num = i;
            return;
        }
    }
}
void
TrPlanestressRotAllman :: computeEgdeNMatrixAt(FloatMatrix &answer, int iedge, GaussPoint *gp)
{
    std::vector< FloatArray > lxy;
    FloatArray l, n;
    IntArray en;
    FEI2dTrQuad qi(1, 2);

    this->computeLocalNodalCoordinates(lxy); // get ready for tranformation into 3d
    qi.edgeEvalN( n, iedge, gp->giveNaturalCoordinates(), FEIVertexListGeometryWrapper(lxy) );
    qi.computeLocalEdgeMapping(en, iedge); // get edge mapping
    this->interp.edgeEvalN( l, iedge, gp->giveNaturalCoordinates(), FEIElementGeometryWrapper(this) );
    answer.resize(3, 6);

    answer.at(1, 1) = answer.at(2, 2) = n.at(1) + n.at(3) / 2.0;
    answer.at(1, 4) = answer.at(2, 5) = n.at(2) + n.at(3) / 2.0;
    answer.at(1, 3) = n.at(3) * ( lxy [ en.at(2) - 1 ].at(2) - lxy [ en.at(1) - 1 ].at(2) ) / 8.0;
    answer.at(1, 6) = -answer.at(1, 3);
    answer.at(2, 3) = n.at(3) * ( lxy [ en.at(2) - 1 ].at(1) - lxy [ en.at(1) - 1 ].at(1) ) / 8.0;
    answer.at(2, 6) = -answer.at(2, 3);
    answer.at(3, 3) = l.at(1);
    answer.at(3, 6) = l.at(2);
}
Beispiel #20
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(UtilsTest, toTextureImageRegion_emptyRegion)
{
    QImage qi(3, 4, QImage::Format_ARGB32);

    {
        cvf::TextureImage i;
        cvfqt::Utils::toTextureImageRegion(qi, cvf::Vec2ui(1, 1), cvf::Vec2ui(0, 0), &i);
        EXPECT_EQ(0, i.width());
        EXPECT_EQ(0, i.height());
    }
    {
        cvf::TextureImage i;
        cvfqt::Utils::toTextureImageRegion(qi, cvf::Vec2ui(1, 1), cvf::Vec2ui(1, 0), &i);
        EXPECT_EQ(0, i.width());
        EXPECT_EQ(0, i.height());
    }
    {
        cvf::TextureImage i;
        cvfqt::Utils::toTextureImageRegion(qi, cvf::Vec2ui(1, 1), cvf::Vec2ui(0, 1), &i);
        EXPECT_EQ(0, i.width());
        EXPECT_EQ(0, i.height());
    }
}
Beispiel #21
0
QPixmap loadIcon(const QString nam, bool forceUseColor)
{
	static ScPixmapCache<QString> pxCache;
	if (pxCache.contains(nam))
		return *pxCache[nam];

	QString iconFilePath(QString("%1%2").arg(ScPaths::instance().iconDir()).arg(nam));
	QPixmap *pm = new QPixmap();
	
	if (!QFile::exists(iconFilePath))
		qWarning("Unable to load icon %s: File not found", iconFilePath.toAscii().constData());
	else
	{
		pm->load(iconFilePath);
		if (pm->isNull())
			qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.toAscii().constData());
		if (PrefsManager::instance()->appPrefs.grayscaleIcons && !forceUseColor)
		{
			QImage qi(pm->toImage());
			int h=qi.height();
			int w=qi.width();
			QRgb c_rgb;
			for (int i=0;i<w;++i)
			{
				for (int j=0;j<h;++j)
				{
					c_rgb=qi.pixel(i,j);
					int k = qMin(qRound(0.3 * qRed(c_rgb) + 0.59 * qGreen(c_rgb) + 0.11 * qBlue(c_rgb)), 255);
					qi.setPixel(i, j, qRgba(k, k, k, qAlpha(c_rgb)));
				}
			}
			*pm=QPixmap::fromImage(qi);
		}
	}
	pxCache.insert(nam, pm);
	return *pm;
}
Beispiel #22
0
/// \brief Two dimensional midpoint displacement fractal.
///
/// For a tile where edges are to be filled by 1d fractals.
/// Size must be a power of 2, array is (size + 1) * (size + 1) with the
/// corners the control points.
void Segment::fill2d(const BasePoint& p1, const BasePoint& p2, 
                     const BasePoint& p3, const BasePoint& p4)
{
    assert(m_points!=0);
    
    // int line = m_res+1;
    
    // calculate the edges first. This is necessary so that segments tile
    // seamlessly note the order in which the edges are calculated and the
    // direction. opposite edges are calculated the same way (eg left->right)
    // so that the top of one tile matches the bottom of another, likewise
    // with sides.
    
    // temporary array used to hold each edge
    float * edge = new float[m_size];
    
    // calc top edge and copy into m_points
    fill1d(p1,p2,edge);
    for (int i=0;i<=m_res;i++) {
        m_points[0*m_size + i] = edge[i];
        checkMaxMin(edge[i]);
    }

    // calc left edge and copy into m_points
    fill1d(p1,p4,edge);
    for (int i=0;i<=m_res;i++) {
        m_points[i*m_size + 0] = edge[i];
        checkMaxMin(edge[i]);
    }
   
    // calc right edge and copy into m_points
    fill1d(p2,p3,edge);
    for (int i=0;i<=m_res;i++) {
        m_points[i*m_size + m_res] = edge[i];
        checkMaxMin(edge[i]);
    }

    // calc bottom edge and copy into m_points
    fill1d(p4,p3,edge);
    for (int i=0;i<=m_res;i++) {
        m_points[m_res*m_size + i] = edge[i];
        checkMaxMin(edge[i]);
    }
    
    // seed the RNG - this is the 5th and last seeding for the tile.
    // it was seeded once for each edge, now once for the tile.
    //srand(p1.seed()*20 + p2.seed()*15 + p3.seed()*10 + p4.seed()*5);
    WFMath::MTRand::uint32 seed[4]={ p1.seed(), p2.seed(), p3.seed(), p4.seed() };
    WFMath::MTRand rng(seed, 4);

    QuadInterp qi(m_res, p1.roughness(), p2.roughness(), p3.roughness(), p4.roughness());

    float f = BasePoint::FALLOFF;
    float depth=0;
    
    // center of m_points is done separately
    int stride = m_res/2;

    //float roughness = (p1.roughness+p2.roughness+p3.roughness+p4.roughness)/(4.0f);
    float roughness = qi.calc(stride, stride);
    m_points[stride*m_size + stride] = qRMD(rng, m_points[0 * m_size + stride],
                                        m_points[stride*m_size + 0],
                                        m_points[stride*m_size + m_res],
                                        m_points[m_res*m_size + stride],
                                        roughness,
                                        f, depth);
                    

    checkMaxMin(m_points[stride*m_size + stride]);

    stride >>= 1;

    // skip across the m_points and fill in the points
    // alternate cross and plus shapes.
    // this is a diamond-square algorithm.
    while (stride) {
      //Cross shape - + contributes to value at X
      //+ . +
      //. X .
      //+ . +
      for (int i=stride;i<m_res;i+=stride*2) {
          for (int j=stride;j<m_res;j+=stride*2) {
              roughness=qi.calc(i,j);
              m_points[j*m_size + i] = qRMD(rng, m_points[(i-stride) + (j+stride) * (m_size)],
                                       m_points[(i+stride) + (j-stride) * (m_size)],
                                       m_points[(i+stride) + (j+stride) * (m_size)],
                                       m_points[(i-stride) + (j-stride) * (m_size)],
                                       roughness, f, depth);
              checkMaxMin(m_points[j*m_size + i]);
          }
      }
 
      depth++;
      //Plus shape - + contributes to value at X
      //. + .
      //+ X +
      //. + .
      for (int i=stride*2;i<m_res;i+=stride*2) {
          for (int j=stride;j<m_res;j+=stride*2) {
              roughness=qi.calc(i,j);
              m_points[j*m_size + i] = qRMD(rng, m_points[(i-stride) + (j) * (m_size)],
                                       m_points[(i+stride) + (j) * (m_size)],
                                       m_points[(i) + (j+stride) * (m_size)],
                                       m_points[(i) + (j-stride) * (m_size)], 
                                       roughness, f , depth);
              checkMaxMin(m_points[j*m_size + i]);
          }
      }
               
      for (int i=stride;i<m_res;i+=stride*2) {
          for (int j=stride*2;j<m_res;j+=stride*2) {
              roughness=qi.calc(i,j);
              m_points[j*m_size + i] = qRMD(rng, m_points[(i-stride) + (j) * (m_size)],
                                       m_points[(i+stride) + (j) * (m_size)],
                                       m_points[(i) + (j+stride) * (m_size)],
                                       m_points[(i) + (j-stride) * (m_size)],
                                       roughness, f, depth);
              checkMaxMin(m_points[j*m_size + i]);
          }
      }

      stride>>=1;
      depth++;
    }
    delete [] edge;
}
Beispiel #23
0
int Stroke::occluders_size() const
{
  return qi();
}
Beispiel #24
0
int Curve::occluders_size() const
{
	return qi();
}
Beispiel #25
0
    bool add(control_ptr ob, long i, long j, T teni, T tenj){
      //	m2::subdivide<T> sub;
      //	m2Ch = sub.subdivide_control(m2Ch);
      //bezier_curve<point_space<3,T> > mCurve(3);
      face_ptr fi = ob->face(i);
      face_ptr fj = ob->face(j);
			
      bezier_curve<point_space<3,typename SPACE::type> > mCurve(4);	
      coordinate_type c0 = fi->calculate_center();	
      coordinate_type c0t = c0 + teni*ob->face(i)->normal();
      coordinate_type c1 = fj->calculate_center();	
      coordinate_type c1t = c1 + tenj*ob->face(j)->normal();			
			
      if (fi->size() != fj->size() ) {
	return false;
      }
			
      mCurve.push_point(c0);
      mCurve.push_point(c0t);	
      mCurve.push_point(c1t);		
      mCurve.push_point(c1);
			
      mCurve.update_knot_vector();
			
			
      Eigen::Quaternion<T>  q1(ob->face(j)->normal());q1.normalize();			
			
      vector<coordinate_type > f0 = fi->coordinate_trace();
      vector<coordinate_type > f1 = fj->coordinate_trace();
			
      long Ni = mCurve.mKnots.size();
      T dt = T(1./T(Ni-1));
      T t = dt*0.5;
      //						for(long ii = 0; ii < 3; ++ii){			
      for(long ii = 0; ii < Ni-1; ++ii){
	coordinate_type Ni = fi->normal();
	Eigen::Quaternion<T>  q0(Ni); q0.normalize();
	coordinate_type de = mCurve.mKnots[ii]-mCurve.mKnots[ii+1];
	de.normalize();
	Eigen::Quaternion<T> qi(de); qi.normalize();
	//
	coordinate_type xe = cross(Ni,-de).normalize();
	T r0 = de.mag();
	T r1 = Ni.mag();
	T o = acos(dot(-de,Ni)/r0/r1);
				
	Eigen::Quaternion<T> dq(cos(o/2.), sin(o/2.)*xe[0], sin(o/2.)*xe[1], sin(o/2.)*xe[2]);
	//				Eigen::Quaternion<T> dq = (qi*q0); //dq[0]*=M_PI;
	//dq.normalize();			
	coordinate_type cen = fi->calculate_center();
	face_vertex_ptr itb = fi->fbegin();
	face_vertex_ptr ite = fi->fend();
				
	construct<SPACE> bevel;
	bevel.bevel_face(ob, fi, 0.0, 0.0);			
				
	bool at_head = false;
	while (!at_head) {
	  at_head = itb == ite;
	  coordinate_type c = itb->coordinate();
	  coordinate_type cp0 = dq.rotate(c-cen);
	  itb->coordinate() = cp0 + (mCurve.mKnots[ii+1]);
	  itb = itb->next();					
	}
				
	fi->update_normal();
	fi->update_center();				
	this->slerp_face(t, fi, fj);				
	//				cen = fi->calculate_center();
	//				itb = fi->fbegin();
	//				at_head = false;
	//				while (!at_head) {
	//					at_head = itb == ite;
	//					coordinate_type c = itb->coordinate();
	//					coordinate_type N = fi->normal();
	//					T o = 0.5*t*M_PI;
	//					Eigen::Quaternion<T> qb(cos(o*0.5), sin(o*0.5)*N[0], sin(o*0.5)*N[1], sin(o*0.5)*N[2]);
	//					qb.normalize();
	//					Eigen::Matrix<T,4,1> cp1 = qb.rotate(c-cen);
	//					//					Eigen::Matrix<T,4,1> cp1 = cp0;
	//					//					itb->coordinate() = cp0 + (mCurve.mKnots[ii] + mCurve.mKnots[ii + 1])*0.5;
	//					itb->coordinate() = cp1 + (mCurve.mKnots[ii+1]);
	//					itb = itb->next();					
	//				}
				
	t += dt;
      }
      graph_skinning<SPACE> gs; //TODO: stitch_faces needs to get moved to a surgery object
      gs.stitch_faces(ob, fi, fj, 0.01);
      return true;
    }
Beispiel #26
0
int main(int argc, char **argv) {
  const std::string storage_path = "exampledb";
  // comment that, for open exists storage.
  if (dariadb::utils::fs::path_exists(storage_path)) {
    dariadb::utils::fs::rm(storage_path);
  }

  // Replace standart logger.
  dariadb::utils::ILogger_ptr log_ptr{new QuietLogger()};
  dariadb::utils::LogManager::start(log_ptr);

  auto storage = dariadb::open_storage(storage_path);
  auto settings = storage->settings();

  auto scheme = dariadb::scheme::Scheme::create(settings);

  auto p1 = scheme->addParam("group.param1");
  auto p2 = scheme->addParam("group.subgroup.param2");
  scheme->save();

  auto m = dariadb::Meas();
  auto start_time = dariadb::timeutil::current_time();

  // write values in interval [currentTime:currentTime+10]
  m.time = start_time;
  for (size_t i = 0; i < 10; ++i) {
    if (i % 2) {
      m.id = p1;
    } else {
      m.id = p2;
    }

    m.time++;
    m.value++;
    m.flag = 100 + i % 2;
    auto status = storage->append(m);
    if (status.writed != 1) {
      std::cerr << "Error: " << dariadb::to_string(status.error) << std::endl;
    }
  }
  // we can get param id`s from scheme
  auto all_params = scheme->ls();
  dariadb::IdArray all_id;
  all_id.reserve(all_params.size());
  all_id.push_back(all_params.idByParam("group.param1"));
  all_id.push_back(all_params.idByParam("group.subgroup.param2"));

  // query writed interval;
  dariadb::QueryInterval qi(all_id, dariadb::Flag(), start_time, m.time);
  dariadb::MeasArray readed_values = storage->readInterval(qi);
  std::cout << "Readed: " << readed_values.size() << std::endl;
  for (auto measurement : readed_values) {
    std::cout << " param: " << all_params[measurement.id]
              << " timepoint: " << dariadb::timeutil::to_string(measurement.time)
              << " value:" << measurement.value << std::endl;
  }

  // query in timepoint;
  dariadb::QueryTimePoint qp(all_id, dariadb::Flag(), m.time);
  dariadb::Id2Meas timepoint = storage->readTimePoint(qp);
  std::cout << "Timepoint: " << std::endl;
  for (auto kv : timepoint) {
    auto measurement = kv.second;
    std::cout << " param: " << all_params[kv.first]
              << " timepoint: " << dariadb::timeutil::to_string(measurement.time)
              << " value:" << measurement.value << std::endl;
  }

  // current values
  dariadb::Id2Meas cur_values = storage->currentValue(all_id, dariadb::Flag());
  std::cout << "Current: " << std::endl;
  for (auto kv : timepoint) {
    auto measurement = kv.second;
    std::cout << " id: " << all_params[kv.first]
              << " timepoint: " << dariadb::timeutil::to_string(measurement.time)
              << " value:" << measurement.value << std::endl;
  }

  // callback
  std::cout << "Callback in interval: " << std::endl;
  Callback callback;
  storage->foreach (qi, &callback);
  callback.wait();

  // callback
  std::cout << "Callback in timepoint: " << std::endl;
  storage->foreach (qp, &callback);
  callback.wait();

  { // stat
    auto stat = storage->stat(dariadb::Id(0), start_time, m.time);
    std::cout << "count: " << stat.count << std::endl;
    std::cout << "time: [" << dariadb::timeutil::to_string(stat.minTime) << " "
              << dariadb::timeutil::to_string(stat.maxTime) << "]" << std::endl;
    std::cout << "val: [" << stat.minValue << " " << stat.maxValue << "]" << std::endl;
    std::cout << "sum: " << stat.sum << std::endl;
  }

  { // statistical functions
    dariadb::statistic::Calculator calc(storage);
    auto all_functions = dariadb::statistic::FunctionFactory::functions();
    std::cout << "available functions: " << std::endl;
    for (auto fname : all_functions) {
      std::cout << " " << fname << std::endl;
    }
    auto result =
        calc.apply(dariadb::Id(0), start_time, m.time, dariadb::Flag(), all_functions);
    for (size_t i = 0; i < result.size(); ++i) {
      auto measurement = result[i];
      std::cout << all_functions[i] << " id: " << all_params[m.id].name
                << " timepoint: " << dariadb::timeutil::to_string(measurement.time)
                << " value:" << measurement.value << std::endl;
    }
  }
}
Beispiel #27
0
MaxCutHyperheuristic::MaxCutHyperheuristic(const MaxCutInstance&mi,
                                           double runtime_limit,
                                           bool validation,
                                           MaxCutCallback *mc, int seed,
                                           std::string* selected) :
  MaxCutHeuristic(mi, runtime_limit, validation, mc) {
  // Step 1: Calculate graph metrics for this instance.
  GraphMetrics gm(mi);
  std::vector<double> metrics;
  gm.AllMetrics(&metrics, NULL);

  // Step 2: Obtain predicted probabilities from each random forest model.
  // Best-performing model information (using streaming alg to select best)
  double bestProbability = -1.0;
  Prob bestProblem = MaxCut;
  std::string bestCode = "";
  int numBest = 1;  // Number tied for best

  // Check the Max-Cut heuristics
  HeuristicFactory factory;
  std::vector<std::string> codes;
  factory.MaxCutHeuristicCodes(&codes);
  for (int i=0; i < codes.size(); ++i) {
    UpdateBestModel(codes[i], MaxCut, metrics, &bestProbability, &bestProblem,
                    &bestCode, &numBest);
  }

  // Check the QUBO heuristics
  factory.QUBOHeuristicCodes(&codes);
  for (int i=0; i < codes.size(); ++i) {
    UpdateBestModel(codes[i], QUBO, metrics, &bestProbability, &bestProblem,
                    &bestCode, &numBest);
  }
  if (selected) {
    *selected = bestCode;
  }

  // Step 3: Run the selected heuristic "H", using callbacks to capture all the
  // reported solutions from "H" and report them for the hyper-heuristic.
  // Because several previous steps may have used random draws or set the
  // random seed, re-set the seed to the original here.
  srand(seed);
  if (bestProblem == MaxCut) {
    // Using a Max-Cut heuristic
    HyperheuristicMaxCutCallback callback(this);
    // Run with our callback and no validation (solutions will be validated
    // with the hyperheuristic, so no need to double validate)
    Heuristic *h = factory.RunMaxCutHeuristic(bestCode, mi, runtime_limit,
                                              false, &callback);
    delete h;  // We don't need to keep around the pointer
  } else if (bestProblem == QUBO) {
    // Using a QUBO heuristic
    HyperheuristicQUBOCallback callback(this, mi);
    QUBOInstance qi(mi);  // Need to construct a QUBOInstance for heuristic
    // Run with our callback and no validation (solutions will be validated
    // with the hyperheuristic, so no need to double validate)
    Heuristic *h = factory.RunQUBOHeuristic(bestCode, qi, runtime_limit,
                                            false, &callback);
    delete h;  // We don't need to keep around the pointer
  }
}