Ejemplo n.º 1
0
        static inline A0_n kernel_atan(const A0_n a0_n)
        {
          const A0 a0 = {a0_n};
          const A0 x = nt2::abs(a0);

          //here x is positive
          const bA0 flag1 = lt(x, single_constant<A0, 0x401a827a>()); //tan3pio8);
          const bA0 flag2 = logical_and(ge(x, single_constant<A0, 0x3ed413cd>()), flag1);
          A0 yy =  if_zero_else(flag1, Pio_2<A0>());
          yy =  select(flag2, Pio_4<A0>(), yy);
          A0 xx =   select(flag1, x, -rec(x));
          xx =  select(flag2, (minusone(x)/oneplus(x)),xx);
          const A0 z = sqr(xx);
          A0 z1 = madd(z,  single_constant<A0, 0x3da4f0d1>(),single_constant<A0, 0xbe0e1b85>());
          const A0 z2 = madd(z,  single_constant<A0, 0x3e4c925f>(),single_constant<A0, 0xbeaaaa2a>());
          z1 = madd(z1, sqr(z), z2);
          return  add(yy, madd(xx, mul( z1, z), xx));
        }
Ejemplo n.º 2
0
uint32 gnGenomeSpec::AddFeature( gnBaseFeature* feat ){
	uint32 count = 0;
	uint32 len = 0;
	uint32 featureI = 0;
	uint32 specListLen = GetSpecListLength();

	for(uint32 specI = 0; specI < specListLen; specI++){
		len = GetSpec(specI)->GetLength();
		gnLocation lt(count, count+len);
		if(feat->IsContainedBy(lt)){
			return featureI + GetSpec(specI)->AddFeature(feat);
		}
		count += len;
		featureI += GetSpec(specI)->GetFeatureListLength();
	}
	//if we get this far then the feature has invalid coordinates
	Throw_gnEx(SeqIndexOutOfBounds());
}
Ejemplo n.º 3
0
int RBST<KEY, VAL, COMP_FUNC, LT_FUNC>::search( KEY key, VAL &value ) {
    int current = root;
    int counter = 0;
    while ( current != -1 ) {
        if ( comp( key, backing_array[current]->key) ) {
            value = backing_array[current]->value;
            return counter;
        } else if ( lt( key, backing_array[current]->key ) ) {
            counter++;
            current = backing_array[current]->left;
        } else {
            counter++;
            current = backing_array[current]->right;
        }
    }
    if ( counter == 0 )
        return -1;
    return counter * -1;
}
Ejemplo n.º 4
0
		void trigger::_m_draw_border(graph_reference graph)
		{
			nana::rectangle r(graph.size());

			::nana::color lt(static_cast<color_rgb>(0x7f7f7f)), rb(static_cast<color_rgb>(0x707070));
			graph.frame_rectangle(r, lt, lt, rb, rb);

			graph.palette(false, colors::button_face);

			paint::draw draw(graph);
			draw.corner(r, 1);

			graph.palette(false, static_cast<color_rgb>(0x919191));

			draw.corner(r.pare_off(1), 1);

			if (element_state::pressed == attr_.e_state)
				graph.rectangle(r, false, static_cast<color_rgb>(0xc3c3c3));
		}
Ejemplo n.º 5
0
	/**
	*	@brief	Marks an element with a tombstone. Tombstones can be consumed by calling insert(), overwriting the tombstone
	*			with new data.
	*/
	void erase(std::uint32_t idx) {
		assert(idx < size());

		// Annihilate slot
		{
			std::unique_lock<std::mutex> l(general_mutex);

			// Update changes
			changes.erase(idx);
		}

		{
			std::unique_lock<std::mutex> lt(tombstones_mutex);

			// Mark tombstone
			const tombstone_range t(idx, 1);
			tombstones.add(t);
		}
	}
Ejemplo n.º 6
0
/* Reduce coefficients of r before calling reduce_add_sub */
static void reduce_add_sub(word32 *r)
{
  word32 pb = 0;
  word32 b;
  word32 mask;
  int i;
  unsigned char t[32];

  for(i=0;i<32;i++)
  {
    pb += m[i];
    b = lt(r[i],pb);
    t[i] = r[i]-pb+(b<<8);
    pb = b;
  }
  mask = b - 1;
  for(i=0;i<32;i++)
    r[i] ^= mask & (r[i] ^ t[i]);
}
Ejemplo n.º 7
0
void ColMsg::get_all_in_all_out(ColMsgList & all_in, ColMsgList & all_out, 
				const ColMsgList & msgs)
{
  Q3PtrListIterator<ColMsg> it(msgs);
  
  for (; it.current() != 0; ++it) {
    ColMsgList & l = (it.current()->is_forward) ? all_in : all_out;
    const QString & hi = it.current()->hierarchical_rank;
    
    unsigned index;
    Q3PtrListIterator<ColMsg> it2(l);
    
    for (index = 0; it2.current() != 0; index += 1, ++it2)
      if (lt(hi, it2.current()->hierarchical_rank))
	break;

    l.insert(index, it.current());
  }
}
Ejemplo n.º 8
0
	static inline A0 atan(const  A0& a0)
	{
	  A0 x, sign;
	  x = nt2::abs(a0);
	  sign = bitofsign(a0);
	  //	bf::tie(sign, x) = sign_and_abs(a0);
	  const A0 flag1 = lt(x, single_constant<A0, 0x401a827a>()); //tan3pio8);
	  const A0 flag2 = b_and(ge(x, single_constant<A0, 0x3ed413cd>()), flag1);
	  A0 yy =  b_notand(flag1, Pio_2<A0>());
	  yy =  select(flag2, Pio_4<A0>(), yy);
	  A0 xx =   select(flag1, x, -rec(x));
	  xx =  select(flag2, (minusone(x)/oneplus(x)),xx);
	  const A0 z = sqr(xx);
	  A0 z1 = madd(z,  single_constant<A0, 0x3da4f0d1>(),single_constant<A0, 0xbe0e1b85>());
	  A0 z2 = madd(z,  single_constant<A0, 0x3e4c925f>(),single_constant<A0, 0xbeaaaa2a>());
	  z1 = madd(z1, sqr(z), z2);
	  yy =  add(yy, madd(xx, mul( z1, z), xx));
	  return b_xor(yy, sign);
	}
Ejemplo n.º 9
0
heapElement binaryHeap<heapElement>::sortHeap(int index) {
    int l = left(index);
    int r = right(index);
    int length = size();

    // if there are no more childnodes, swap the value at the current index with the value at
    // end of the array, sort the value at the current index then remove and return the
    // last array element (the minimum element)
    if (length <= l) {
        heapElement value = heap[swap(index, length) - 1];
        bubble(index);
        heap.pop_back();
        return value;
    }

    // if the right node is in range and less then the left node then swap
    // the child with the right node, otherwise swap with the left
    sortHeap(swap(index, length > r && lt(r,l) ? r : l ));
}
Ejemplo n.º 10
0
 void display(std::ostream & out, unsigned indent) const {
     svector<symbol> names;
     dictionary<info>::iterator it  = m_info.begin();
     dictionary<info>::iterator end = m_info.end();
     for (; it != end; ++it) {
         names.push_back(it->m_key);
     }
     std::sort(names.begin(), names.end(), lt());
     svector<symbol>::iterator it2  = names.begin();
     svector<symbol>::iterator end2 = names.end();
     for (; it2 != end2; ++it2) {
         for (unsigned i = 0; i < indent; i++) out << " ";
         out << *it2;
         info d;
         d.second = 0;
         m_info.find(*it2, d);
         SASSERT(d.second);
         out << " (" << d.first << ") " << d.second << "\n";
     }
 }
Rect Transform::transform(const Rect& bounds) const
{
    Rect r;
    vec2 lt( bounds.left,  bounds.top    );
    vec2 rt( bounds.right, bounds.top    );
    vec2 lb( bounds.left,  bounds.bottom );
    vec2 rb( bounds.right, bounds.bottom );

    lt = transform(lt);
    rt = transform(rt);
    lb = transform(lb);
    rb = transform(rb);

    r.left   = floorf(min(lt[0], rt[0], lb[0], rb[0]) + 0.5f);
    r.top    = floorf(min(lt[1], rt[1], lb[1], rb[1]) + 0.5f);
    r.right  = floorf(max(lt[0], rt[0], lb[0], rb[0]) + 0.5f);
    r.bottom = floorf(max(lt[1], rt[1], lb[1], rb[1]) + 0.5f);

    return r;
}
Ejemplo n.º 12
0
TEST( ElemMatchValueMatchExpression, MatchesElementMultiple ) {
    BSONObj baseOperand1 = BSON( "$gt" << 1 );
    BSONObj baseOperand2 = BSON( "$lt" << 10 );
    BSONObj notMatch1 = BSON( "a" << BSON_ARRAY( 0 << 1 ) );
    BSONObj notMatch2 = BSON( "a" << BSON_ARRAY( 10 << 11 ) );
    BSONObj match = BSON( "a" << BSON_ARRAY( 0 << 5 << 11 ) );
    auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() );
    ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand1[ "$gt" ] ).isOK() );
    auto_ptr<ComparisonMatchExpression> lt( new ComparisonMatchExpression() );
    ASSERT( lt->init( "", ComparisonMatchExpression::LT, baseOperand2[ "$lt" ] ).isOK() );

    ElemMatchValueMatchExpression op;
    ASSERT( op.init( "a" ).isOK() );
    op.add( gt.release() );
    op.add( lt.release() );

    ASSERT( !op.matchesSingleElement( notMatch1[ "a" ] ) );
    ASSERT( !op.matchesSingleElement( notMatch2[ "a" ] ) );
    ASSERT( op.matchesSingleElement( match[ "a" ] ) );
}
Ejemplo n.º 13
0
void XmlTest::linesToXml() {

	rdf::Timer dt;

	qDebug() << "image path: " << mConfig.imagePath();

	// load image
	QImage img(mConfig.imagePath());
	cv::Mat imgCv = Image::qImage2Mat(img);

	// binarize
	rdf::BinarizationSuAdapted binarizeImg(imgCv, cv::Mat());
	binarizeImg.compute();
	cv::Mat bwImg = binarizeImg.binaryImage();
	qInfo() << "binarised in" << dt;

	// find lines
	rdf::LineTrace lt(bwImg);
	lt.setAngle(0.0);
	lt.compute();
	QVector<rdf::Line> allLines = lt.getLines();
	qInfo() << allLines.size() << "lines detected in" << dt;

	// init parser
	PageXmlParser parser;
	parser.read(mConfig.xmlPath());

	auto root = parser.page()->rootRegion();

	// test writing lines
	for (const rdf::Line& cL : allLines) {

		QSharedPointer<rdf::SeparatorRegion> pSepR(new rdf::SeparatorRegion());
		pSepR->setLine(cL.line());
		root->addUniqueChild(pSepR);
	}

	parser.write(PageXmlParser::imagePathToXmlPath(mConfig.outputPath()), parser.page());
	
	qInfo() << mConfig.imagePath() << "lines computed and written in" << dt;
}
int main(int argc, char* argv[]){
/*
	cout << "****************" << endl;
	for(int i = 0; i < argc; ++i){
		cout << argv[i] << endl;
	}
	cout<< "**********" << endl;
*/
	char* port = argv[2];
	char* hostfile = argv[4];
	char* faulty = argv[6];
	int f = atoi(faulty);
	cout << f << endl;
	char* commander_id = argv[8];
	int cmdid = atoi(commander_id);
	
	if(argc > 9){
		char* order = argv[10];
		cout << "I'm the Commander" << endl;
		if(order[0] == 'r'){
			Commander cm(port, hostfile, f, cmdid, RETREAT);
			cm.mainLoop();
		}
		else if (order[0] == 'a'){
			Commander cm(port, hostfile, f, cmdid, ATTACK);
			cm.mainLoop();
		} 
		else{
			cout << "please input retreat or attack for the cmd" << endl;
			exit(1);
		}		
	}
	else{
		cout << "I'm the Lieutenant" << endl;
		Lieutenant lt(port, hostfile, f, cmdid);
		lt.mainLoop();
	}
	
	return 0;
}
Ejemplo n.º 15
0
/* Heapify-down the element in the queue at the provided index
 *
 * Requires:
 *   - A valid min bin heap (array) is provided
 *     - The value of the heap elements index into an array of vertices
 *   - An array of vertices is provided with an accessible .dist member
 *     - 0 dist indicates infinity
 *   - The head of the heap starts at index 1
 *
 * Guarantees:
 *   - The value at the provided index will be heapify-down'd
 *   - The heap will still be a valid min bin heap
 *   - The new index for the value at the provided index will be returned
 */
int heapify_down( vertex_t *v
                , uint16_t *q
                , uint16_t i
                )
{
    int stop = 0;

    do { // heapify-down
        int c1 = 2*i;
        int c2 = 2*i+1;
        stop = (c1 > VERT_IDX_MAX || c2 > VERT_IDX_MAX) // reached bottom
            || !( gt(v[q[i]].dist, v[q[c1]].dist)
               || gt(v[q[i]].dist, v[q[c2]].dist)
                ); // parent < child
        if(!stop) {
            int s = lt(v[q[c1]].dist, v[q[c2]].dist) ? c1 : c2;
            swap(v, q, i, s); // swap child with shortest distance
            i = s;
        }
    } while(!stop);
    return i;
}
Ejemplo n.º 16
0
void insertion_sort(item_t *a, int l, int r)
{
    /* find the min value as the sentinel */
    int min;
    int i;

    for (min = l, i = min + 1; i <= r; i++) {
        if (a[min] > a[i]) {
            min = i;
        }
    }

    for (i = l + 1; i <= r; i++) {
        int j    = i;
        item_t v = a[j];

        for (; lt(v, a[j-1]); j--) {
            a[j] = a[j-1];
        }

        a[j] = v;
    }
}
Ejemplo n.º 17
0
 void display(std::ostream & out, unsigned indent, bool smt2_style, bool include_descr) const {
     svector<symbol> names;
     dictionary<info>::iterator it  = m_info.begin();
     dictionary<info>::iterator end = m_info.end();
     for (; it != end; ++it) {
         names.push_back(it->m_key);
     }
     std::sort(names.begin(), names.end(), lt());
     svector<symbol>::iterator it2  = names.begin();
     svector<symbol>::iterator end2 = names.end();
     for (; it2 != end2; ++it2) {
         for (unsigned i = 0; i < indent; i++) out << " ";
         if (smt2_style)
             out << ':';
         char const * s = it2->bare_str();
         unsigned n = static_cast<unsigned>(strlen(s));
         for (unsigned i = 0; i < n; i++) {
             if (smt2_style && s[i] == '_')
                 out << '-';
             else if (!smt2_style && s[i] == '-')
                 out << '_';
             else if (s[i] >= 'A' && s[i] <= 'Z')
                 out << (s[i] - 'A' + 'a');
             else 
                 out << s[i];
         }
         info d;
         m_info.find(*it2, d);
         SASSERT(d.m_descr);
         out << " (" << d.m_kind << ")";
         if (include_descr)
             out << " " << d.m_descr;
         if (d.m_default != 0)
             out << " (default: " << d.m_default << ")";
         out << "\n";
     }
 }
Ejemplo n.º 18
0
// _RebuildClipping
void
Painter::_RebuildClipping()
{
	if (fBaseRenderer) {
		fBaseRenderer->reset_clipping(!fClippingRegion);
		if (fClippingRegion) {
			int32 count = fClippingRegion->CountRects();
			for (int32 i = 0; i < count; i++) {
				BRect r = fClippingRegion->RectAt(i);
				// NOTE: The rounding here appears to give somewhat
				// different results compared to Be's implementation,
				// though I was unable to figure out the difference
				BPoint lt(r.LeftTop());
				BPoint rb(r.RightBottom());
				// offset to bottom right corner of pixel before transformation
				rb += BPoint(1.0, 1.0);
				// apply transformation
				lt += fOrigin;
				lt.x *= fScale;
				lt.y *= fScale;
				rb += fOrigin;
				rb.x *= fScale;
				rb.y *= fScale;
				// undo offset to bottom right corner after transformation
				rb -= BPoint(1.0, 1.0);
//				fBaseRenderer->add_clip_box(floorf(lt.x),
//											floorf(lt.y),
//											ceilf(rb.x),
//											ceilf(rb.y));
				fBaseRenderer->add_clip_box(roundf(lt.x),
											roundf(lt.y),
											roundf(rb.x),
											roundf(rb.y));
			}
		}
	}
}
Ejemplo n.º 19
0
// FillRoundRect
void
Painter::FillRoundRect(const BRect& r, float xRadius, float yRadius,
					   const pattern& p) const
{
	BPoint lt(r.left, r.top);
	BPoint rb(r.right, r.bottom);
	_Transform(&lt, false);
	_Transform(&rb, false);

	// account for stricter interpretation of coordinates in AGG
	// the rectangle ranges from the top-left (.0, .0)
	// to the bottom-right (.9999, .9999) corner of pixels
	rb.x += 1.0;
	rb.y += 1.0;

	_Transform(&xRadius);
	_Transform(&yRadius);

	agg::rounded_rect rect;
	rect.rect(lt.x, lt.y, rb.x, rb.y);
	rect.radius(xRadius, yRadius);

	_FillPath(rect, p);
}
Ejemplo n.º 20
0
int SetDepDirection( DepInfo &edd, int commLevel, Collect &result)
    {
      if (commLevel < 0)
          return commLevel;
      DepRel eq(DEPDIR_EQ, 0), lt(DEPDIR_LE, -1);
      int i;
      for ( i = 0; i < commLevel; i++) {
        DepRel e1 = edd.Entry(i,i) & lt; 
        if (DebugDep()) {
           std::cerr << "at common loop level " << i << ":" << e1.toString() << "\n";
        }
        if (!e1.IsTop()) {
          DepInfo edd1( edd);
          edd1.Entry( i,i) = e1;
          assert(!edd1.IsTop());
          result(edd1);
        }
        DepRel &e2 = edd.Entry(i,i);
        e2  &= eq;
        if (e2.IsTop())
          return i;
      }
      return i+1;
    }
Ejemplo n.º 21
0
 static inline A0 atan(const  A0& a0)
 {
     typedef typename meta::scalar_of<A0>::type sA0;
     static const A0 tan3pio8  = double_constant<A0, 0x4003504f333f9de6ll>();
     static const A0 Twothird = double_constant<A0, 0x3fe51eb851eb851fll>();
     static const A0 tanpio8 = double_constant<A0, 0x3fda827999fcef31ll>();
     A0 x =  abs(a0);
     const A0 flag1 = lt(x,  double_constant<A0, 0x4003504f333f9de6ll>());              //tan3pio8
     const A0 flag2 = b_and(ge(x, double_constant<A0, 0x3fda827999fcef31ll>()), flag1); //tanpio8
     A0 yy =  b_notand(flag1, Pio_2<A0>());
     yy =  select(flag2, Pio_4<A0>(), yy);
     A0 xx =   select(flag1, x, -rec(x));
     xx =  select(flag2, minusone(x)/oneplus(x),xx);
     A0 z = sqr(xx);
     z = z*horner< NT2_HORNER_COEFF_T(sA0, 5,
                                      (0xbfec007fa1f72594ll,
                                       0xc03028545b6b807all,
                                       0xc052c08c36880273ll,
                                       0xc05eb8bf2d05ba25ll,
                                       0xc0503669fd28ec8ell)
                                     )>(z)/
         horner< NT2_HORNER_COEFF_T(sA0, 6,
                                    (0x3ff0000000000000ll,
                                     0x4038dbc45b14603cll,
                                     0x4064a0dd43b8fa25ll,
                                     0x407b0e18d2e2be3bll,
                                     0x407e563f13b049eall,
                                     0x4068519efbbd62ecll)
                                   )>(z);
     z = fma(xx, z, xx);
     //	static const A0 morebits = double_constant<A0, 0x3c91a62633145c07ll>();
     z = seladd(flag2, z, mul(Half<A0>(),  double_constant<A0, 0x3c91a62633145c07ll>()));
     z = z+b_notand(flag1, double_constant<A0, 0x3c91a62633145c07ll>());
     yy = yy + z;
     return b_xor(yy, bitofsign(a0));
 }
Ejemplo n.º 22
0
void BVH4iIntersector1::occluded(BVH4i* bvh, Ray& ray)
{
    /* near and node stack */
    __aligned(64) NodeRef stack_node[3*BVH4i::maxDepth+1];

    /* setup */
    const mic3f rdir16      = rcp_safe(mic3f(ray.dir.x,ray.dir.y,ray.dir.z));
    const mic_f inf         = mic_f(pos_inf);
    const mic_f zero        = mic_f::zero();

    const Node      * __restrict__ nodes = (Node     *)bvh->nodePtr();
    const Triangle1 * __restrict__ accel = (Triangle1*)bvh->triPtr();

    stack_node[0] = BVH4i::invalidNode;
    stack_node[1] = bvh->root;
    size_t sindex = 2;

    const mic_f org_xyz      = loadAOS4to16f(ray.org.x,ray.org.y,ray.org.z);
    const mic_f dir_xyz      = loadAOS4to16f(ray.dir.x,ray.dir.y,ray.dir.z);
    const mic_f rdir_xyz     = loadAOS4to16f(rdir16.x[0],rdir16.y[0],rdir16.z[0]);
    const mic_f org_rdir_xyz = org_xyz * rdir_xyz;
    const mic_f min_dist_xyz = broadcast1to16f(&ray.tnear);
    const mic_f max_dist_xyz = broadcast1to16f(&ray.tfar);

    const unsigned int leaf_mask = BVH4I_LEAF_MASK;

    while (1)
    {
        NodeRef curNode = stack_node[sindex-1];
        sindex--;

        while (1)
        {
            /* test if this is a leaf node */
            if (unlikely(curNode.isLeaf(leaf_mask))) break;

            const Node* __restrict__ const node = curNode.node(nodes);
            const float* __restrict const plower = (float*)node->lower;
            const float* __restrict const pupper = (float*)node->upper;

            prefetch<PFHINT_L1>((char*)node + 0);
            prefetch<PFHINT_L1>((char*)node + 64);

            /* intersect single ray with 4 bounding boxes */
            const mic_f tLowerXYZ = load16f(plower) * rdir_xyz - org_rdir_xyz;
            const mic_f tUpperXYZ = load16f(pupper) * rdir_xyz - org_rdir_xyz;
            const mic_f tLower = mask_min(0x7777,min_dist_xyz,tLowerXYZ,tUpperXYZ);
            const mic_f tUpper = mask_max(0x7777,max_dist_xyz,tLowerXYZ,tUpperXYZ);

            sindex--;
            curNode = stack_node[sindex];

            const Node* __restrict__ const next = curNode.node(nodes);
            prefetch<PFHINT_L2>((char*)next + 0);
            prefetch<PFHINT_L2>((char*)next + 64);

            const mic_f tNear = vreduce_max4(tLower);
            const mic_f tFar  = vreduce_min4(tUpper);
            const mic_m hitm = le(0x8888,tNear,tFar);
            const mic_f tNear_pos = select(hitm,tNear,inf);


            /* if no child is hit, continue with early popped child */
            if (unlikely(none(hitm))) continue;
            sindex++;

            const unsigned long hiti = toInt(hitm);
            const unsigned long pos_first = bitscan64(hiti);
            const unsigned long num_hitm = countbits(hiti);

            /* if a single child is hit, continue with that child */
            curNode = ((unsigned int *)plower)[pos_first];
            if (likely(num_hitm == 1)) continue;

            /* if two children are hit, push in correct order */
            const unsigned long pos_second = bitscan64(pos_first,hiti);
            if (likely(num_hitm == 2))
            {
                const unsigned int dist_first  = ((unsigned int*)&tNear)[pos_first];
                const unsigned int dist_second = ((unsigned int*)&tNear)[pos_second];
                const unsigned int node_first  = curNode;
                const unsigned int node_second = ((unsigned int*)plower)[pos_second];

                if (dist_first <= dist_second)
                {
                    stack_node[sindex] = node_second;
                    sindex++;
                    assert(sindex < 3*BVH4i::maxDepth+1);
                    continue;
                }
                else
                {
                    stack_node[sindex] = curNode;
                    curNode = node_second;
                    sindex++;
                    assert(sindex < 3*BVH4i::maxDepth+1);
                    continue;
                }
            }

            /* continue with closest child and push all others */
            const mic_f min_dist = set_min_lanes(tNear_pos);
            const unsigned old_sindex = sindex;
            sindex += countbits(hiti) - 1;
            assert(sindex < 3*BVH4i::maxDepth+1);

            const mic_m closest_child = eq(hitm,min_dist,tNear);
            const unsigned long closest_child_pos = bitscan64(closest_child);
            const mic_m m_pos = andn(hitm,andn(closest_child,(mic_m)((unsigned int)closest_child - 1)));
            const mic_i plower_node = load16i((int*)plower);
            curNode = ((unsigned int*)plower)[closest_child_pos];
            compactustore16i(m_pos,&stack_node[old_sindex],plower_node);
        }



        /* return if stack is empty */
        if (unlikely(curNode == BVH4i::invalidNode)) break;


        /* intersect one ray against four triangles */

        //////////////////////////////////////////////////////////////////////////////////////////////////

        const Triangle1* tptr  = (Triangle1*) curNode.leaf(accel);
        prefetch<PFHINT_L1>(tptr + 3);
        prefetch<PFHINT_L1>(tptr + 2);
        prefetch<PFHINT_L1>(tptr + 1);
        prefetch<PFHINT_L1>(tptr + 0);

        const mic_i and_mask = broadcast4to16i(zlc4);

        const mic_f v0 = gather_4f_zlc(and_mask,
                                       (float*)&tptr[0].v0,
                                       (float*)&tptr[1].v0,
                                       (float*)&tptr[2].v0,
                                       (float*)&tptr[3].v0);

        const mic_f v1 = gather_4f_zlc(and_mask,
                                       (float*)&tptr[0].v1,
                                       (float*)&tptr[1].v1,
                                       (float*)&tptr[2].v1,
                                       (float*)&tptr[3].v1);

        const mic_f v2 = gather_4f_zlc(and_mask,
                                       (float*)&tptr[0].v2,
                                       (float*)&tptr[1].v2,
                                       (float*)&tptr[2].v2,
                                       (float*)&tptr[3].v2);

        const mic_f e1 = v1 - v0;
        const mic_f e2 = v0 - v2;
        const mic_f normal = lcross_zxy(e1,e2);
        const mic_f org = v0 - org_xyz;
        const mic_f odzxy = msubr231(org * swizzle(dir_xyz,_MM_SWIZ_REG_DACB), dir_xyz, swizzle(org,_MM_SWIZ_REG_DACB));
        const mic_f den = ldot3_zxy(dir_xyz,normal);
        const mic_f rcp_den = rcp(den);
        const mic_f uu = ldot3_zxy(e2,odzxy);
        const mic_f vv = ldot3_zxy(e1,odzxy);
        const mic_f u = uu * rcp_den;
        const mic_f v = vv * rcp_den;

#if defined(__BACKFACE_CULLING__)
        const mic_m m_init = (mic_m)0x1111 & (den > zero);
#else
        const mic_m m_init = 0x1111;
#endif
        const mic_m valid_u = ge(m_init,u,zero);
        const mic_m valid_v = ge(valid_u,v,zero);
        const mic_m m_aperture = le(valid_v,u+v,mic_f::one());

        const mic_f nom = ldot3_zxy(org,normal);
        const mic_f t = rcp_den*nom;

        if (unlikely(none(m_aperture))) continue;

        mic_m m_final  = lt(lt(m_aperture,min_dist_xyz,t),t,max_dist_xyz);

#if defined(__USE_RAY_MASK__)
        const mic_i rayMask(ray.mask);
        const mic_i triMask = swDDDD(gather16i_4i_align(&tptr[0].v2,&tptr[1].v2,&tptr[2].v2,&tptr[3].v2));
        const mic_m m_ray_mask = (rayMask & triMask) != mic_i::zero();
        m_final &= m_ray_mask;
#endif

#if defined(__INTERSECTION_FILTER__)

        /* did the ray hit one of the four triangles? */
        while (any(m_final))
        {
            const mic_f temp_t  = select(m_final,t,max_dist_xyz);
            const mic_f min_dist = vreduce_min(temp_t);
            const mic_m m_dist = eq(min_dist,temp_t);
            const size_t vecIndex = bitscan(toInt(m_dist));
            const size_t triIndex = vecIndex >> 2;
            const Triangle1  *__restrict__ tri_ptr = tptr + triIndex;
            const mic_m m_tri = m_dist^(m_dist & (mic_m)((unsigned int)m_dist - 1));
            const mic_f gnormalx = mic_f(tri_ptr->Ng.x);
            const mic_f gnormaly = mic_f(tri_ptr->Ng.y);
            const mic_f gnormalz = mic_f(tri_ptr->Ng.z);
            const int geomID = tri_ptr->geomID();
            const int primID = tri_ptr->primID();
            Geometry* geom = ((Scene*)bvh->geometry)->get(geomID);

            if (likely(!geom->hasOcclusionFilter1())) break;

            if (runOcclusionFilter1(geom,ray,u,v,min_dist,gnormalx,gnormaly,gnormalz,m_tri,geomID,primID))
                break;

            m_final ^= m_tri; /* clear bit */
        }
#endif

        if (unlikely(any(m_final)))
        {
            ray.geomID = 0;
            return;
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////

    }
}
Ejemplo n.º 23
0
void NitfWriter::doneFile()
{
    finishOutput();

    try
    {
        ::nitf::Record record(NITF_VER_21);
        ::nitf::FileHeader header = record.getHeader();
        header.getFileHeader().set("NITF");
        header.getComplianceLevel().set(m_cLevel);
        header.getSystemType().set(m_sType);
        header.getOriginStationID().set(m_oStationId);
        if (m_fileTitle.empty())
        	m_fileTitle = FileUtils::getFilename(m_nitfFilename);
        header.getFileTitle().set(m_fileTitle);
        header.getClassification().set(m_fileClass);
        header.getMessageCopyNum().set("00000");
        header.getMessageNumCopies().set("00000");
        header.getEncrypted().set("0");
        header.getBackgroundColor().setRawData(const_cast<char*>("000"), 3);
        header.getOriginatorName().set(m_origName);
        header.getOriginatorPhone().set(m_origPhone);
        header.getSecurityGroup().getClassificationSystem().set(
            m_securityClassificationSystem);
        header.getSecurityGroup().getControlAndHandling().set(
            m_securityControlAndHandling);
        header.getSecurityGroup().getClassificationText().set(m_sic);

        ::nitf::DESegment des = record.newDataExtensionSegment();

        des.getSubheader().getFilePartType().set("DE");
        des.getSubheader().getTypeID().set("LIDARA DES");
        des.getSubheader().getVersion().set("01");
        des.getSubheader().getSecurityClass().set(m_securityClass);
        ::nitf::FileSecurity security = record.getHeader().getSecurityGroup();
        des.getSubheader().setSecurityGroup(security.clone());

        ::nitf::TRE usrHdr("LIDARA DES", "raw_data");
        usrHdr.setField("raw_data", "not");
        ::nitf::Field fld = usrHdr.getField("raw_data");
        fld.setType(::nitf::Field::BINARY);

        std::streambuf *buf = m_oss.rdbuf();
        long size = buf->pubseekoff(0, m_oss.end);
        buf->pubseekoff(0, m_oss.beg);

        std::vector<char> bytes(size);
        buf->sgetn(bytes.data(), size);
        m_oss.clear();

        des.getSubheader().setSubheaderFields(usrHdr);

        ::nitf::ImageSegment image = record.newImageSegment();
        ::nitf::ImageSubheader subheader = image.getSubheader();

        BOX3D bounds =  reprojectBoxToDD(m_srs, m_bounds);

        //NITF decimal degree values for corner coordinates only has a
        // precision of 3 after the decimal. This may cause an invalid
        // polygon due to rounding errors with a small tile. Therefore
        // instead of rounding min values will use the floor value and
        // max values will use the ceiling values.
        bounds.minx = (floor(bounds.minx * 1000)) / 1000.0;
        bounds.miny = (floor(bounds.miny * 1000)) / 1000.0;
        bounds.maxx = (ceil(bounds.maxx * 1000)) / 1000.0;
        bounds.maxy = (ceil(bounds.maxy * 1000)) / 1000.0;

        double corners[4][2];
        corners[0][0] = bounds.maxy;
        corners[0][1] = bounds.minx;
        corners[1][0] = bounds.maxy;
        corners[1][1] = bounds.maxx;
        corners[2][0] = bounds.miny;
        corners[2][1] = bounds.maxx;
        corners[3][0] = bounds.miny;
        corners[3][1] = bounds.minx;
        subheader.setCornersFromLatLons(NRT_CORNERS_DECIMAL, corners);

        subheader.getImageSecurityClass().set(m_imgSecurityClass);
        subheader.setSecurityGroup(security.clone());
        if (m_imgDate.size())
            subheader.getImageDateAndTime().set(m_imgDate);

        ::nitf::BandInfo info;
        ::nitf::LookupTable lt(0,0);
        info.init(" ",    /* The band representation, Nth band */
                  " ",      /* The band subcategory */
                  "N",      /* The band filter condition */
                  "   ",    /* The band standard image filter code */
                  0,        /* The number of look-up tables */
                  0,        /* The number of entries/LUT */
                  lt);     /* The look-up tables */

        std::vector< ::nitf::BandInfo> bands;
        bands.push_back(info);
        subheader.setPixelInformation(
            "INT",      /* Pixel value type */
            8,         /* Number of bits/pixel */
            8,         /* Actual number of bits/pixel */
            "R",       /* Pixel justification */
            "NODISPLY",     /* Image representation */
            "VIS",     /* Image category */
            1,         /* Number of bands */
            bands);

        subheader.setBlocking(
            8,   /*!< The number of rows */
            8,  /*!< The number of columns */
            8, /*!< The number of rows/block */
            8,  /*!< The number of columns/block */
            "B");                /*!< Image mode */

        //Image Header fields to set
        subheader.getImageId().set("None");
        subheader.getImageTitle().set(m_imgIdentifier2);

        // 64 char string
        std::string zeros(64, '0');

        std::unique_ptr< ::nitf::BandSource> band(new ::nitf::MemorySource(
            const_cast<char*>(zeros.c_str()),
            zeros.size() /* memory size */,
            0 /* starting offset */,
            1 /* bytes per pixel */,
            0 /*skip*/));
        ::nitf::ImageSource iSource;
        iSource.addBand(*band);

        //AIMIDB
        ::nitf::TRE aimidbTre("AIMIDB");

        //LIDAR defaults
        if (m_imgDate.size())
        	aimidbTre.setField("ACQUISITION_DATE", m_imgDate);
        aimidbTre.setField("MISSION_NO", "UNKN");
        aimidbTre.setField("MISSION_IDENTIFICATION", "NOT AVAIL.");
        aimidbTre.setField("FLIGHT_NO", "00");
        aimidbTre.setField("CURRENT_SEGMENT", "AA");
        aimidbTre.setField("START_TILE_COLUMN", "001");
        aimidbTre.setField("START_TILE_ROW", "00001");
        aimidbTre.setField("END_SEGMENT", "00");
        aimidbTre.setField("END_TILE_COLUMN", "001");
        aimidbTre.setField("END_TILE_ROW", "00001");

        for (auto& s : m_aimidb)
        {
            StringList v = Utils::split2(s, ':');
            if (v.size() != 2)
            {
                std::ostringstream oss;
                oss << "Invalid name/value for AIMIDB '" << s <<
                    "'.  Format: <name>:<value>.";
                throw oss.str();
            }
            Utils::trim(v[0]);
            Utils::trim(v[1]);
            aimidbTre.setField(v[0], v[1]);
        }
        subheader.getExtendedSection().appendTRE(aimidbTre);

		//if IDATIM is empty set it equal to AIMIDB.ACQUISITION_DATE
        if(!m_imgDate.size())
        {
        	m_imgDate=aimidbTre.getField("ACQUISITION_DATE").toString();
			if (m_imgDate.size())
				subheader.getImageDateAndTime().set(m_imgDate);
        }

        //ACFTB
        ::nitf::TRE acftbTre("ACFTB");

        //LIDAR defaults
        acftbTre.setField("AC_MSN_ID", "NOT AVAILABLE");
        acftbTre.setField("SCENE_SOURCE", " ");
        if (m_imgDate.size()>7)
        	acftbTre.setField("PDATE", m_imgDate.substr(0,8));
        acftbTre.setField("MPLAN", "999");
        acftbTre.setField("LOC_ACCY", "000.00");
        acftbTre.setField("ROW_SPACING", "0000000");
        acftbTre.setField("ROW_SPACING_UNITS", "u");
        acftbTre.setField("COL_SPACING", "0000000");
        acftbTre.setField("COL_SPACING_UNITS", "u");
        acftbTre.setField("FOCAL_LENGTH", "999.99");

        for (auto& s : m_acftb)
        {
            StringList v = Utils::split2(s, ':');
            if (v.size() != 2)
            {
                std::ostringstream oss;
                oss << "Invalid name/value for ACFTB '" << s <<
                    "'.  Format: <name>:<value>.";
                throw oss.str();
            }
            Utils::trim(v[0]);
            Utils::trim(v[1]);
            acftbTre.setField(v[0], v[1]);
        }
        subheader.getExtendedSection().appendTRE(acftbTre);

        ::nitf::Writer writer;
        ::nitf::IOHandle output_io(m_nitfFilename.c_str(),
            NITF_ACCESS_WRITEONLY, NITF_CREATE);
        writer.prepare(output_io, record);

        ::nitf::SegmentWriter sWriter = writer.newDEWriter(0);

        ::nitf::SegmentMemorySource sSource(bytes.data(), size, 0, 0, false);
        sWriter.attachSource(sSource);

        ::nitf::ImageWriter iWriter = writer.newImageWriter(0);
        iWriter.attachSource(iSource);

        writer.write();
        output_io.close();
    }
    catch (except::Throwable & t)
    {
        std::ostringstream oss;
        // std::cout << t.getTrace();
        throw pdal_error(t.getMessage());
    }
}
Ejemplo n.º 24
0
      stack_node[0] = BVH4i::invalidNode;      
      stack_node[1] = bvh->root;

      size_t sindex = 2;

      const vfloat16 org_xyz      = loadAOS4to16f(ray.org.x,ray.org.y,ray.org.z);
      const vfloat16 dir_xyz      = loadAOS4to16f(ray.dir.x,ray.dir.y,ray.dir.z);
      const vfloat16 rdir_xyz     = loadAOS4to16f(rdir16.x[0],rdir16.y[0],rdir16.z[0]);
      const vfloat16 org_rdir_xyz = org_xyz * rdir_xyz;
      const vfloat16 min_dist_xyz = vfloat16::broadcast(&ray.tnear);
      vfloat16       max_dist_xyz = vfloat16::broadcast(&ray.tfar);
      const vfloat16 time         = vfloat16::broadcast(&ray.time);
	  
      const unsigned int leaf_mask = BVH4I_LEAF_MASK;
      const vbool16 m7777 = 0x7777; 
      const vbool16 m_rdir0 = lt(m7777,rdir_xyz,vfloat16::zero());
      const vbool16 m_rdir1 = ge(m7777,rdir_xyz,vfloat16::zero());
	  
      while (1)
	{
	  NodeRef curNode = stack_node[sindex-1];
	  sindex--;
            
	  traverse_single_intersect(curNode,
				    sindex,
				    rdir_xyz,
				    org_rdir_xyz,
				    min_dist_xyz,
				    max_dist_xyz,
				    time,
				    stack_node,
Ejemplo n.º 25
0
int binaryHeap<heapElement>::bubble (int index)
{ return index < 2 || lt(parent(index), index) ? index : bubble(swap(index, parent(index))); };
Ejemplo n.º 26
0
int gte(struct tree *lhs, struct tree *rhs) {
	return lt(rhs, lhs);
}
Ejemplo n.º 27
0
bool value::operator<(value const & other) const {
    if (get_name() == other.get_name())
        return lt(other);
    else
        return get_name() < other.get_name();
}
Ejemplo n.º 28
0
 bool operator()(expr * t1, expr * t2) const {
     if (t1->get_ref_count() < t2->get_ref_count())
         return true;
     return (t1->get_ref_count() == t2->get_ref_count()) && lt(t1, t2);
 }
Ejemplo n.º 29
0
void TeaonlyRaptor::createMatrixA(const std::vector<RaptorSymbol>& symbols) {
    
    /*           The matrix A                */
    /*
                  K               S       H
      +-----------------------+-------+-------+
      |                       |       |       |
    S |        G_LDPC         |  I_S  | 0_SxH |
      |                       |       |       |
      +-----------------------+-------+-------+
      |                               |       |
    H |        G_Half                 |  I_H  |
      |                               |       |
      +-------------------------------+-------+
      |                                       |
      |                                       |
    K |                 G_LT                  |
      |                                       |
      |                                       |
      +---------------------------------------+
    */
    
    matrixA_.clear();
    std::vector<unsigned char> zero_row;
    for(int j = 0; j < l_; j++) {
        zero_row.push_back(0);
    }

    std::vector<std::vector<unsigned int> > xorMatrix;
    ldpc(xorMatrix);
    for (int i = 0; i < s_; i++) {
        std::vector<unsigned char> row;
        row = zero_row;
        row[k_ + i] = 1;
        for(int j = 0; j < xorMatrix[i].size(); j++) {
            row[ xorMatrix[i][j]] = 1;
        }
        matrixA_.push_back(row);
    }
    
    half(xorMatrix);
    for (int i = 0; i < h_; i++) {
        std::vector<unsigned char> row;
        row = zero_row;
        row[k_ + s_ + i] = 1;
        for(int j = 0; j < xorMatrix[i].size(); j++) {
            row[ xorMatrix[i][j]] = 1;
        }
        matrixA_.push_back(row);
    }
    
    std::vector<unsigned int> lt_row;
    for(int i=0; i < symbols.size(); i++) {
        std::vector<unsigned char> row;
        row = zero_row;
        lt(symbols[i].esi, lt_row);
        for(int i = 0; i < lt_row.size(); i++) {
            row[lt_row[i]] = 1;
        }
        matrixA_.push_back(row);
    }
    
}
Ejemplo n.º 30
0
Archivo: main.cpp Proyecto: spease/lr
int main(int const argc, char const * const * const argv)
{
  Grammar g;
  /*
  g |= NT("goal") >>= NT("expr");
  g |= NT("expr") >>= NT("term") + T("+") + NT("expr") | NT("term");
  g |= NT("term") >>= NT("factor") + T("*") + NT("term") | NT("factor");
  g |= NT("factor") >>= T("0") | T("1") | T("2") | T("3") | T("4") | T("5") | T("6") | T("7") | T("8") | T("9");
  */

  g |= NT("goal") >>= NT("expr");
  g |= NT("expr") >>= NT("term") + T("+") + NT("expr");
  g |= NT("expr") >>= NT("term");
  g |= NT("term") >>= NT("factor") + T("*") + NT("term");
  g |= NT("term") >>= NT("factor");
  g |= NT("factor") >>= T("id");

  /*
  g |= NT("E") >>= NT("E") + T("*") + NT("B");
  g |= NT("E") >>= NT("E") + T("+") + NT("B");
  g |= NT("E") >>= NT("B");
  g |= NT("B") >>= T("0");
  g |= NT("B") >>= T("1");
  */

  //g |= NT("B") >>= T("hello") + T(" ") + T("world") | T("goodbye") + T(" ") + T("world");

  /*
  g |= NT("start_$") >>= NT("start");
  g |= NT("start") >>= NT("start") + NT("expr");
  g |= NT("start");
  g |= NT("expr") >>= T("NR");
  g |= NT("expr") >>= NT("expr") + T("+") + NT("expr");
  */

  LRParser p(LRTable::Type::LR, 1, g);
  LexText plt(TEST_FILEPATH);
#ifndef NDEBUG
  std::cout << "====================----- Parsing -----====================" << std::endl;
#endif
  if(p.parse(plt))
  {
    std::cout << "Parsing success." << std::endl;
  }
#ifndef NDEBUG
  std::cout << "==================================================" << std::endl;
#endif

#ifndef NDEBUG
  std::cout << "====================----- " << TEST_FILEPATH << " -----====================" << std::endl;
  LexText lt(TEST_FILEPATH);
  Symbol s=END();
  do
  {
    s = lt.pop();
    std::cout << s.toString() << " ";
  }
  while(s != END());
  std::cout << std::endl;
  std::cout << "==================================================" << std::endl;

  
  std::cout << "====================----- Grammar -----====================" << std::endl;
  std::cout << g.toString();
  std::cout << "==================================================" << std::endl;
#endif

  return 0;
}