//round all neuronal node coordinates, and compute the average min distance matches for all places the neurons go through
NeuronDistSimple neuron_score_rounding_nearest_neighbor(const NeuronTree *p1, const NeuronTree *p2)
{
	NeuronDistSimple ss;

	if (!p1 || !p2) return ss;
	V3DLONG p1sz = p1->listNeuron.size(), p2sz = p2->listNeuron.size();
	if (p1sz<1 || p2sz<1) return ss;

	double sum12, sum21;
	V3DLONG nseg1, nseg2;
	double sum12big, sum21big;
	V3DLONG nseg1big, nseg2big;
	sum12 = dist_directional_swc_1_2(nseg1, nseg1big, sum12big, p1, p2);
	sum21 = dist_directional_swc_1_2(nseg2, nseg2big, sum21big, p2, p1);

	qDebug() << "sum12="<<sum12 << "npoints1="<< nseg1 << "sum21="<< sum21 << "npoint2="<< nseg2;
	qDebug() << "sum12big="<<sum12big << "npoints1big="<< nseg1big << "sum21big="<< sum21big << "npoint2big="<< nseg2big;

	ss.dist_allnodes = (sum12/nseg1 + sum21/nseg2)/2.0;
	if (nseg1big>0)
	{
		if (nseg2big>0)
			ss.dist_apartnodes = (sum12big/nseg1big + sum21big/nseg2big)/2.0;
		else
			ss.dist_apartnodes = (sum12big/nseg1big);
	}
	else
	{
		if (nseg2big>0)
			ss.dist_apartnodes = (sum21big/nseg2big);
		else
			ss.dist_apartnodes = 0;
	}
	ss.percent_apartnodes = (double(nseg1big)/nseg1 + double(nseg2big)/nseg2)/2.0;

	return ss;
}
//round all neuronal node coordinates, and compute the average min distance matches for all places the neurons go through
NeuronDistSimple neuron_score_rounding_nearest_neighbor(const NeuronTree *p1, const NeuronTree *p2,bool bmenu)
{
	NeuronDistSimple ss;

    //===
    if(bmenu)
    {
        bool ok1;
#ifndef USE_Qt5
        V3DLONG d_thres_new = QInputDialog::getInteger(0, "change the default distance threshold",
                                                       "The visible-spatial-distance threshold of two neurons: ", d_thres, 2, 20, 1, &ok1);
#else
        V3DLONG d_thres_new = QInputDialog::getInt(0, "change the default distance threshold",
                                                       "The visible-spatial-distance threshold of two neurons: ", d_thres, 2, 20, 1, &ok1);
#endif
        if (ok1)
        {
            d_thres = d_thres_new;
        }
    }
    //===


	if (!p1 || !p2) return ss;
	V3DLONG p1sz = p1->listNeuron.size(), p2sz = p2->listNeuron.size();
    if (p1sz<2 || p2sz<2) {
        cout<<"Input neurons has too few nodes, distance calculation requires at least two nodes." <<endl;
        return ss; //requires two nodes at least
     }

	double sum12, sum21;
	V3DLONG nseg1, nseg2;
	double sum12big, sum21big;
    double maxdist12 = -1, maxdist21 = -1; //set as some big numbers
	V3DLONG nseg1big, nseg2big;
    sum12 = dist_directional_swc_1_2(nseg1, nseg1big, sum12big, p1, p2, maxdist12);
    sum21 = dist_directional_swc_1_2(nseg2, nseg2big, sum21big, p2, p1, maxdist21);

    //qDebug() << "sum12="<<sum12 << "npoints1="<< nseg1 << "sum21="<< sum21 << "npoint2="<< nseg2;
    //qDebug() << "sum12big="<<sum12big << "npoints1big="<< nseg1big << "sum21big="<< sum21big << "npoint2big="<< nseg2big;
    //qDebug() << "maxdist12="<<maxdist12 << "maxdist21="<< maxdist21;


    ss.dist_12_allnodes = sum12/nseg1;
    ss.dist_21_allnodes = sum21/nseg2;

    ss.dist_allnodes = (sum12/nseg1 + sum21/nseg2)/2.0;
	if (nseg1big>0)
	{
		if (nseg2big>0)
			ss.dist_apartnodes = (sum12big/nseg1big + sum21big/nseg2big)/2.0;
		else
			ss.dist_apartnodes = (sum12big/nseg1big);
	}
	else
	{
		if (nseg2big>0)
			ss.dist_apartnodes = (sum21big/nseg2big);
		else
			ss.dist_apartnodes = 0;
	}
	ss.percent_apartnodes = (double(nseg1big)/nseg1 + double(nseg2big)/nseg2)/2.0;

    ss.dist_max = (maxdist12<maxdist21) ? maxdist12 : maxdist21; //this max distance should refelect the meaningful measure.
                                                                 // Becasue the two neurons (tracts) can have different starting and ending locations,
                                                                 // the bigger one of  maxdist12 and maxdist21 could simply reflect the big difference of
                                                                 // of the starting locations of the two tracts. Thus I use the smaller one, which
                                                                // should correspond better to the max distance at the truck part of two tracts. PHC 20140318.
	return ss;
}