Пример #1
0
	ECBody& ECScene::spawnBox(
	   const std::string& Name,
		const double& mass,
		const chrono::ChVector<>& position,
		const chrono::ChVector<>& size,
		const chrono::ChQuaternion<>& rotation,
		const bool& fixed) {

		ECBody& _ret = createBody(Name);

		chrono::ChSharedPtr<chrono::ChBoxShape> _box(new chrono::ChBoxShape);
		_box->GetBoxGeometry().Size = size;

		_ret->SetRot(rotation);
		_ret->SetPos(position);
		_ret->SetMass(mass);
		_ret->GetAssets().push_back(_box);

		_ret->GetCollisionModel()->ClearModel();
		_ret->GetCollisionModel()->AddBox(size.x, size.y, size.z);
		_ret->GetCollisionModel()->BuildModel();
		_ret->SetCollide(true);
		_ret->SetBodyFixed(fixed);

		_ret.refresh();

		return _ret;
	}
Пример #2
0
// draw a box directly to display memory
int _near Drawbox_Cmd( LPTSTR pszCmdLine )
{
	register TCHAR *pszArg, *pszLine;
	int nTop, nLeft, nBottom, nRight, nStyle, nAttribute = -1, nFill = -1, n, nFlags = 0, nShade;

	if (( pszCmdLine == NULL ) || ( *pszCmdLine == _TEXT('\0') ))
		return ( Usage( DRAWBOX_USAGE ));

	// get the arguments & colors
	if ( sscanf( pszCmdLine, _TEXT("%d%d%d%d%d%n"), &nTop, &nLeft, &nBottom, &nRight, &nStyle, &n ) == 6 ) {

		pszLine = pszCmdLine + n;
		nAttribute = GetColors( pszLine, 0 );

		// check for a FILL color
		if (( *pszLine ) && ( _strnicmp( first_arg( pszLine ), BOX_FILL, 3 ) == 0 ) && (( pszArg = first_arg( next_arg( pszLine, 1 ))) != NULL )) {

			if ( _strnicmp( pszArg, BRIGHT, 3 ) == 0 ) {
				// set intensity bit
				nFill = 0x80;
				if (( pszArg = first_arg( next_arg( pszLine, 1 ))) == NULL )
					return ( Usage( DRAWBOX_USAGE ));
			} else
				nFill = 0;

			if (( nShade = color_shade( pszArg )) <= 15 ) {
				nFill |= ( nShade << 4 );
				next_arg( pszLine, 1 );
			}
		}

		// check for a SHADOW or ZOOM
		while ( *pszLine ) {
			if ( _strnicmp( pszLine, BOX_SHADOW, 3 ) == 0 )
				nFlags |= BOX_SHADOWED;
			else if ( _strnicmp( pszLine, BOX_ZOOM, 3 ) == 0 )
				nFlags |= BOX_ZOOMED;
			next_arg( pszLine, 1 );
		}
	}

	if (( nAttribute == -1 ) || ( verify_row_col( nTop, nLeft )) || ( verify_row_col( nBottom, nRight )))
		return ( Usage( DRAWBOX_USAGE ));

	if ( nLeft == 999 ) {
		if (( nLeft = (( GetScrCols() - nRight ) / 2 )) < 0 )
			nLeft = 0;
		nRight += nLeft;
	}

	if ( nTop == 999 ) {
		if (( nTop = (( GetScrRows() - nBottom ) / 2 )) < 0 )
			nTop = 0;
		nBottom += nTop;
	}

	_box( nTop, nLeft, nBottom, nRight, nStyle, nAttribute, nFill, nFlags, 1 );

	return 0;
}
Пример #3
0
int  EFILE::domine2PBest(Particle&_a) {

      std::vector<double> _box(nobjectives),_box2(nobjectives),_box3(nobjectives);
      bool _flag=true;
      //calculate the box of both particles
      for (int _i = 0; _i < nobjectives; _i++){
        if( EPS[_i]!=0) {
        _box[_i] = (int) floor ((fabs(tlb[_i]-_a.fx[_i]) / EPS[_i]));
        _box2[_i] = (int)floor ((fabs(tlb[_i]-_a.fxpbest[_i]) / EPS[_i]));
        } else {
           _box[_i]=0;
           _box2[_i]=0;
        }

        //_box[_i] = (int) floor ((_a[_i] / EPS[_i]));
        //_box2[_i] = (int)floor ((_b[_i] / EPS[_i]));
        //_box3[_i] = (_box[_i]<_box2[_i])?_box[_i]*EPS[_i]:_box2[_i]*EPS[_i];//
        _box3[_i] = (int)_box[_i]*EPS[_i];
        //if they are in the same box
        if(_box[_i]!=_box2[_i])_flag=false;
      }
      if(_flag==true){//check for dominance
        int anterior = 0, mejor;

        for(int _i=0;_i<nobjectives;_i++){
          if(_a.fx[_i] <_a.fxpbest[_i])	mejor = 1;
          else if(_a.fxpbest[_i]<_a.fx[_i])mejor = -1;
          else mejor = 0;
          if(mejor!=anterior&&anterior!=0&&mejor!=0){
      if(euclideanDistance(_a.fx,_box3)<euclideanDistance(_a.fxpbest,_box3))
        return 1;
      else return -1;	}
          if(mejor!=0) anterior = mejor;
        }
        //      if(anterior==1) return true;
        //else return false;
        return(anterior);

      }
      int anterior = 0, mejor;
      for(int _i=0;_i<nobjectives;_i++){
        if(_box[_i] <_box2[_i])	mejor = 1;
        else if(_box2[_i]<_box[_i])mejor = -1;
        else mejor = 0;
        if(mejor!=anterior&&anterior!=0&&mejor!=0)return 11;
        if(mejor!=0) anterior = mejor;
      }
      return(anterior);


}
Пример #4
0
// draw a box directly to display memory
int drawbox_cmd(int argc, char **argv)
{
	char *arg, *pszLine;
	int top, left, bottom, right, style, attribute = -1, fill = -1;
	int box_flags = 0;

	// get the arguments & colors
	if ((argc >= 7) && (sscanf(argv[1],"%d%d%d%d%d",&top,&left,&bottom,&right,&style) == 5)) {

		pszLine = argv[6];
		attribute = GetColors(pszLine,0);

		// check for a FILL color
		if ((*pszLine) && (_strnicmp(first_arg(pszLine),BOX_FILL,3) == 0) && ((arg = first_arg(next_arg(pszLine,1))) != NULL)) {

			if (_strnicmp(arg,BRIGHT,3) == 0) {
				// set intensity bit
				fill = 0x80;
				if ((arg = first_arg(next_arg(pszLine,1))) == NULL)
					return (usage(DRAWBOX_USAGE));
			} else
				fill = 0;

			if ((argc = color_shade(arg)) <= 15) {
				fill |= (argc << 4);
				(void)next_arg(pszLine,1);
			}
		}

		// check for a SHADOW or ZOOM
		while (*pszLine) {
			if (_strnicmp(pszLine,BOX_SHADOW,3) == 0)
				box_flags |= BOX_SHADOWED;
			else if (_strnicmp(pszLine,BOX_ZOOM,3) == 0)
				box_flags |= BOX_ZOOMED;
			(void)next_arg(pszLine,1);
		}
	}

	if ((attribute == -1) || (verify_row_col(top,left)) || (verify_row_col(bottom,right)))
		return (usage(DRAWBOX_USAGE));

	_box(top,left,bottom,right,style,attribute,fill,box_flags,1);

	return 0;
}
Пример #5
0
static void _writeHeaderFile(const String& ns)
{
    const char format[] =
        "\n"
        "#ifndef _%s_namespace_h\n"
        "#define _%s_namespace_h\n"
        "\n"
        "#include <Pegasus/Repository/MRRTypes.h>\n"
        "\n"
        "PEGASUS_NAMESPACE_BEGIN\n"
        "\n"
        "extern const MRRNameSpace %s_namespace;\n"
        "\n"
        "PEGASUS_NAMESPACE_END\n"
        "\n"
        "#endif /* _%s_namespace_h */\n"
        ;

    String path = ns + "_namespace.h";
    FILE* os = fopen(*Str(path), "wb");

    if (!os)
    {
        fprintf(stderr, "cimmofl: failed to open \"%s\" for write\n", 
            *Str(path));
        exit(1);
    }

    _box(os, "CAUTION: THIS FILE WAS GENERATED BY CIMMOFL; "
        "PLEASE DO NOT EDIT IT.");
    fprintf(stderr, "\n");

    fprintf(os, format, *Str(ns), *Str(ns), *Str(ns), *Str(ns));

    fclose(os);
}
Пример #6
0
awpImage* TLFFaceImageDescriptor::GetFaceImageForPredictor(awpImage* img, awpRect* faceRect)
{

    awpRect box  = GetFaceBoxForPredictor(faceRect);
    awpRect box1 = GetFaceBoxForPredictor(NULL);

    if (faceRect == NULL)
        box = box1;
    if (faceRect != NULL)
    {
    TLFRect _box(box);
    if (_box.RectOverlap(box1) < 0.3)
        return NULL;
        }


    int w = awpRectWidth(box);
    int h = awpRectHeight(box);

      if (w < h)
      {
         w = h;
      }
      else
      {
        h = w;
      }

      awpPoint cent;
      cent.X = (box.left + box.right) / 2;
      cent.Y = (box.top + box.bottom) / 2;
      box.left = cent.X - w/ 2;
      box.right = cent.X + w / 2;
      box.top  = cent.Y - h / 2;
      box.bottom = cent.Y + h / 2;

      awpRect r;
      r.left = box.left < 0 ? 0:box.left;
      r.right = box.right > img->sSizeX?img->sSizeX: box.right;
      r.top  = box.top < 0 ? 0: box.top;
      r.bottom = box.bottom > img->sSizeY ? img->sSizeY : box.bottom;
      if (r.right - r.left == 0)
        return NULL;

      awpImage* img1 = NULL;
      awpCopyRect(img, &img1, &r);

      w = r.right - r.left;
      h = r.bottom - r.top;
	  double scale = (double)w / (double)h;
      if (w > h)
      {
        w = 256;
        h = (int)floor(w / scale + 0.5);
      }
      else
      {
        h = 256;
        w = (int)floor(h*scale);
      }

      awpResizeBilinear(img1, w, h);
      //box = r;
      //scale descriptor
      scale = (double)256 / (r.right - r.left);
      for (int i = 0; i < 24; i++)
      {
         awpPoint p = GetPoint(i);
         p.X = (AWPSHORT)floor((p.X - r.left)*scale + 0.5);
		 p.Y = (AWPSHORT)floor((p.Y - r.top)*scale + 0.5);
         SetPoint(i, p);
      }
      awpPoint p1;
      awpPoint p = m_roi.GetRoi().p;
      p1 = m_roi.GetRoi().p1;
	  p.X = (AWPSHORT)floor((p.X - r.left)*scale + 0.5);
	  p.Y = (AWPSHORT)floor((p.Y - r.top)*scale + 0.5);
	  p1.X = (AWPSHORT)floor((p1.X - r.left)*scale + 0.5);
	  p1.Y = (AWPSHORT)floor((p1.Y - r.top)*scale + 0.5);
      SetEyes(p,p1);

      return img1;
}
Пример #7
0
double cv::kmeans( InputArray _data, int K,
                   InputOutputArray _bestLabels,
                   TermCriteria criteria, int attempts,
                   int flags, OutputArray _centers )
{
    const int SPP_TRIALS = 3;
    Mat data0 = _data.getMat();
    bool isrow = data0.rows == 1;
    int N = isrow ? data0.cols : data0.rows;
    int dims = (isrow ? 1 : data0.cols)*data0.channels();
    int type = data0.depth();

    attempts = std::max(attempts, 1);
    CV_Assert( data0.dims <= 2 && type == CV_32F && K > 0 );
    CV_Assert( N >= K );

    Mat data(N, dims, CV_32F, data0.ptr(), isrow ? dims * sizeof(float) : static_cast<size_t>(data0.step));

    _bestLabels.create(N, 1, CV_32S, -1, true);

    Mat _labels, best_labels = _bestLabels.getMat();
    if( flags & CV_KMEANS_USE_INITIAL_LABELS )
    {
        CV_Assert( (best_labels.cols == 1 || best_labels.rows == 1) &&
                   best_labels.cols*best_labels.rows == N &&
                   best_labels.type() == CV_32S &&
                   best_labels.isContinuous());
        best_labels.copyTo(_labels);
    }
    else
    {
        if( !((best_labels.cols == 1 || best_labels.rows == 1) &&
                best_labels.cols*best_labels.rows == N &&
                best_labels.type() == CV_32S &&
                best_labels.isContinuous()))
            best_labels.create(N, 1, CV_32S);
        _labels.create(best_labels.size(), best_labels.type());
    }
    int* labels = _labels.ptr<int>();

    Mat centers(K, dims, type), old_centers(K, dims, type), temp(1, dims, type);
    std::vector<int> counters(K);
    std::vector<Vec2f> _box(dims);
    Vec2f* box = &_box[0];
    double best_compactness = DBL_MAX, compactness = 0;
    RNG& rng = theRNG();
    int a, iter, i, j, k;

    if( criteria.type & TermCriteria::EPS )
        criteria.epsilon = std::max(criteria.epsilon, 0.);
    else
        criteria.epsilon = FLT_EPSILON;
    criteria.epsilon *= criteria.epsilon;

    if( criteria.type & TermCriteria::COUNT )
        criteria.maxCount = std::min(std::max(criteria.maxCount, 2), 100);
    else
        criteria.maxCount = 100;

    if( K == 1 )
    {
        attempts = 1;
        criteria.maxCount = 2;
    }

    const float* sample = data.ptr<float>(0);
    for( j = 0; j < dims; j++ )
        box[j] = Vec2f(sample[j], sample[j]);

    for( i = 1; i < N; i++ )
    {
        sample = data.ptr<float>(i);
        for( j = 0; j < dims; j++ )
        {
            float v = sample[j];
            box[j][0] = std::min(box[j][0], v);
            box[j][1] = std::max(box[j][1], v);
        }
    }

    for( a = 0; a < attempts; a++ )
    {
        double max_center_shift = DBL_MAX;
        for( iter = 0;; )
        {
            swap(centers, old_centers);

            if( iter == 0 && (a > 0 || !(flags & KMEANS_USE_INITIAL_LABELS)) )
            {
                if( flags & KMEANS_PP_CENTERS )
                    generateCentersPP(data, centers, K, rng, SPP_TRIALS);
                else
                {
                    for( k = 0; k < K; k++ )
                        generateRandomCenter(_box, centers.ptr<float>(k), rng);
                }
            }
            else
            {
                if( iter == 0 && a == 0 && (flags & KMEANS_USE_INITIAL_LABELS) )
                {
                    for( i = 0; i < N; i++ )
                        CV_Assert( (unsigned)labels[i] < (unsigned)K );
                }

                // compute centers
                centers = Scalar(0);
                for( k = 0; k < K; k++ )
                    counters[k] = 0;

                for( i = 0; i < N; i++ )
                {
                    sample = data.ptr<float>(i);
                    k = labels[i];
                    float* center = centers.ptr<float>(k);
                    j=0;
#if CV_ENABLE_UNROLLED
                    for(; j <= dims - 4; j += 4 )
                    {
                        float t0 = center[j] + sample[j];
                        float t1 = center[j+1] + sample[j+1];

                        center[j] = t0;
                        center[j+1] = t1;

                        t0 = center[j+2] + sample[j+2];
                        t1 = center[j+3] + sample[j+3];

                        center[j+2] = t0;
                        center[j+3] = t1;
                    }
#endif
                    for( ; j < dims; j++ )
                        center[j] += sample[j];
                    counters[k]++;
                }

                if( iter > 0 )
                    max_center_shift = 0;

                for( k = 0; k < K; k++ )
                {
                    if( counters[k] != 0 )
                        continue;

                    // if some cluster appeared to be empty then:
                    //   1. find the biggest cluster
                    //   2. find the farthest from the center point in the biggest cluster
                    //   3. exclude the farthest point from the biggest cluster and form a new 1-point cluster.
                    int max_k = 0;
                    for( int k1 = 1; k1 < K; k1++ )
                    {
                        if( counters[max_k] < counters[k1] )
                            max_k = k1;
                    }

                    double max_dist = 0;
                    int farthest_i = -1;
                    float* new_center = centers.ptr<float>(k);
                    float* old_center = centers.ptr<float>(max_k);
                    float* _old_center = temp.ptr<float>(); // normalized
                    float scale = 1.f/counters[max_k];
                    for( j = 0; j < dims; j++ )
                        _old_center[j] = old_center[j]*scale;

                    for( i = 0; i < N; i++ )
                    {
                        if( labels[i] != max_k )
                            continue;
                        sample = data.ptr<float>(i);
                        double dist = normL2Sqr(sample, _old_center, dims);

                        if( max_dist <= dist )
                        {
                            max_dist = dist;
                            farthest_i = i;
                        }
                    }

                    counters[max_k]--;
                    counters[k]++;
                    labels[farthest_i] = k;
                    sample = data.ptr<float>(farthest_i);

                    for( j = 0; j < dims; j++ )
                    {
                        old_center[j] -= sample[j];
                        new_center[j] += sample[j];
                    }
                }

                for( k = 0; k < K; k++ )
                {
                    float* center = centers.ptr<float>(k);
                    CV_Assert( counters[k] != 0 );

                    float scale = 1.f/counters[k];
                    for( j = 0; j < dims; j++ )
                        center[j] *= scale;

                    if( iter > 0 )
                    {
                        double dist = 0;
                        const float* old_center = old_centers.ptr<float>(k);
                        for( j = 0; j < dims; j++ )
                        {
                            double t = center[j] - old_center[j];
                            dist += t*t;
                        }
                        max_center_shift = std::max(max_center_shift, dist);
                    }
                }
            }

            if( ++iter == MAX(criteria.maxCount, 2) || max_center_shift <= criteria.epsilon )
                break;

            // assign labels
            Mat dists(1, N, CV_64F);
            double* dist = dists.ptr<double>(0);
            parallel_for_(Range(0, N),
                          KMeansDistanceComputer(dist, labels, data, centers));
            compactness = 0;
            for( i = 0; i < N; i++ )
            {
                compactness += dist[i];
            }
        }

        if( compactness < best_compactness )
        {
            best_compactness = compactness;
            if( _centers.needed() )
                centers.copyTo(_centers);
            _labels.copyTo(best_labels);
        }
    }

    return best_compactness;
}