⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jtrackergui.java

📁 该代码仿真了雷达信号图像中目标的跟踪算法,采用了java编写的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		/* This method runs when the user clicks on the right panel. */		public void mousePressed(MouseEvent evt)		{			// If dragging is already in progress, just return.			if (dragging)				return;			// Start dragging the image that the user clicked (if any).			if (!animating) //Don't allow dragging if it's animating.			{   				// Begin dragging the sensor.				if ( evt.getX() >= sensorX && evt.getX() < sensorX + sensorWidth && evt.getY() >= sensorY && evt.getY() < sensorY + sensorHeight )				{					dragging = true;					draggingjet = false;					offsetx = evt.getX() - sensorX;					offsety = evt.getY() - sensorY;				}				// Begin dragging the jet.  If the user clicks on a point occupied by both the jet and				// the radar, the jet is selected.				if ( evt.getX() >= jetX && evt.getX() < jetX + jetWidth && evt.getY() >= jetY && evt.getY() < jetY + jetHeight )				{					dragging = true;					draggingjet = true;					offsetx = evt.getX() - jetX;					offsety = evt.getY() - jetY;				}			}			return;		} // end mousePressed()		/* End the drag operation, if one is in progress. */		public void mouseReleased(MouseEvent evt) 		{ 			if (dragging == false)				return;			dragging = false;		} // end mouseReleased()		/* Continue the drag operation if one is in progress. Move the image that is being dragged to the current		 * mouse position.  But clamp it so that it can't be more than halfway off the screen. */		public void mouseDragged(MouseEvent evt)		{			// If no dragging operation is in progess, just return.			if (dragging == false)            	return;			// Dragging the sensor.			if(!draggingjet)			{				// Get new postion of image.				sensorX = evt.getX() - offsetx;				sensorY = evt.getY() - offsety;				// Clamp (x,y) to a permitted range, as described above.				if (sensorX < - sensorWidth / 2)					sensorX = - sensorWidth / 2;				else if (sensorX + sensorWidth/2 > getSize().width)					sensorX = getSize().width - sensorWidth / 2;				if (sensorY < - sensorHeight / 2)					sensorY = - sensorHeight / 2;				else if (sensorY + sensorHeight/2 > getSize().height)					sensorY = getSize().height - sensorHeight / 2;				// Update the sensor position to match the position of the image.				sensorXmeter = (sensorX-50+sensorWidth/2)*(xmax-xmin)/(getWidth()-70)+xmin;				sensorYmeter = (-sensorY-20-sensorHeight/2+getHeight())*(ymax-ymin)/(getHeight()-40)+ymin;				// Make the sensor position input fields reflect the new position.				lp.Xsensor.setText(Integer.toString((int)sensorXmeter));				lp.Ysensor.setText(Integer.toString((int)sensorYmeter));			}			// Dragging the jet.			else			{				// Get new postion of image.				jetX = evt.getX() - offsetx;				jetY = evt.getY() - offsety;				/* Clamp (x,y) to a permitted range, as described above. */				if (jetX < - jetWidth / 2)					jetX = - jetWidth / 2;				else if (jetX + jetWidth/2 > getSize().width)					jetX = getSize().width - jetWidth / 2;				if (jetY < - jetHeight / 2)					jetY = - jetHeight / 2;				else if (jetY + jetHeight/2 > getSize().height)					jetY = getSize().height - jetHeight / 2;				// Update the target position to match the position of the image.				jetXmeter = (jetX-50+jetWidth/2)*(xmax-xmin)/(getWidth()-70)+xmin;				jetYmeter = (-jetY-20-jetHeight/2+getHeight())*(ymax-ymin)/(getHeight()-40)+ymin;				// Make the initial position input fields reflect the new position.				lp.Xin.setText(Integer.toString((int)(jetXmeter)) + ", " + Integer.toString((int)(jetYmeter)));			}			// Redraw the canvas, with the images in their new positions.			repaint();		}  // end mouseDragged()		/* MouseEvent methods that aren't used are still defined. */		public void mouseClicked(MouseEvent evt) { }		public void mouseEntered(MouseEvent evt) { }		public void mouseExited(MouseEvent evt) { }		public void mouseMoved(MouseEvent evt) { }		/* This is the method that does all the filtering calculations, and also displays the graphics.		 * It is called using the repaint() method, or rp.repaint() if calling from outside the RightPanel		 * class. */		public void paintComponent(Graphics page)		{			super.paintComponent(page);			setBackground(Color.white);			Dimension d = new Dimension(getWidth(), getHeight());			page.clearRect(0,0,d.width,d.height);			wtotal=0;			if (animating)			{				double rError=generator.nextGaussian()*rStdv;				double r_dotError = generator.nextGaussian()*rDotStdv;				double phiError = generator.nextGaussian()*phiStdvRad;				double r = Math.pow(Math.pow(path[0][frame]-xsensor,2)+Math.pow(path[1][frame]-ysensor,2),0.5) + rError;				double r_dot = (1.0/r)*((path[0][frame]-xsensor)*path[2][frame]+(path[1][frame]-ysensor)*path[3][frame]) + r_dotError;				double phi = Math.atan2(path[1][frame]-ysensor,path[0][frame]-xsensor) + phiError;				measErrorPanel.error[frame]=Math.sqrt(Math.pow(r,2)+Math.pow(r-rError,2) - 2*r*(r-rError)*Math.cos(phiError));;				for (int count=0; count<numParts; count++)				{					parts.xPosition[count]=parts.xPosition[count]+parts.xVelocity[count]*1.0/fps+Qval*generator.nextGaussian();					parts.yPosition[count]=parts.yPosition[count]+parts.yVelocity[count]*1.0/fps+Qval*generator.nextGaussian();					parts.xVelocity[count]=parts.xVelocity[count]+Qval*generator.nextGaussian();					parts.yVelocity[count]=parts.yVelocity[count]+Qval*generator.nextGaussian();					double r_x = Math.pow(Math.pow(parts.xPosition[count]-xsensor,2) + Math.pow(parts.yPosition[count]-ysensor,2),0.5);					double rdot_x = ((parts.xPosition[count]-xsensor)*parts.xVelocity[count] + (parts.yPosition[count]-ysensor)*parts.yVelocity[count])/r_x;					double phi_x = Math.atan2(parts.yPosition[count]-ysensor, parts.xPosition[count]-xsensor);					parts.weight[count]=Math.exp(-0.5*(Math.pow(r-r_x,2)/rVar + Math.pow(r_dot-rdot_x,2)/rdotVar + Math.pow(phi-phi_x,2)/phiVar));					wtotal=wtotal+parts.weight[count];				}				xhat[0][frame]=0;				xhat[1][frame]=0;				xhat[2][frame]=0;				xhat[3][frame]=0;				for (int count=0; count<numParts; count++)				{					parts.weight[count] = (wtotal==0) ? 1.0/numParts : parts.weight[count]/wtotal;					xhat[0][frame]=xhat[0][frame]+parts.xPosition[count]*parts.weight[count];					xhat[1][frame]=xhat[1][frame]+parts.yPosition[count]*parts.weight[count];					xhat[2][frame]=xhat[2][frame]+parts.xVelocity[count]*parts.weight[count];					xhat[3][frame]=xhat[3][frame]+parts.yVelocity[count]*parts.weight[count];				}				resampled= (cp.resBox.isSelected()) ? parts.resample() : parts;			}			// Plot both sets of particles			if(run)			{				resampled.pcolor=Color.yellow;				parts.pcolor=Color.green;				if(cp.showOrg.isSelected())					parts.plotParticles(page,xmin,xmax,ymin,ymax,d);				if(cp.showRes.isSelected())					resampled.plotParticles(page,xmin,xmax,ymin,ymax,d);				if(frame<length-1)					parts=resampled;			}			// Draw the sensor			sensorX = (int)((sensorXmeter - xmin)/(xmax-xmin)*(d.width-70)+50-sensorWidth/2);			sensorY = d.height - (int)((sensorYmeter-ymin)/(ymax-ymin)*(d.height-40))-20-sensorHeight/2;			page.drawImage(radar, sensorX, sensorY, sensorWidth, sensorHeight, null, null);			if(run)			{				for (int count=1; count<=frame; count++)				{					x1 = (int)(((path[0][count-1]-xmin)/(xmax-xmin))*(d.width-70))+50;					x2 = (int)(((path[0][count]-xmin)/(xmax-xmin))*(d.width-70))+50;					y1 = d.height - (int)(((path[1][count-1]-ymin)/(ymax-ymin))*(d.height-40))-20;					y2 = d.height - (int)(((path[1][count]-ymin)/(ymax-ymin))*(d.height-40))-20;					page.setColor(Color.black);					page.drawLine(x1,y1,x2,y2);					xhat1 = (int)(((xhat[0][count-1]-xmin)/(xmax-xmin))*(d.width-70))+50;					xhat2 = (int)(((xhat[0][count]-xmin)/(xmax-xmin))*(d.width-70))+50;					yhat1 = d.height - (int)(((xhat[1][count-1]-ymin)/(ymax-ymin))*(d.height-40))-20;					yhat2 = d.height - (int)(((xhat[1][count]-ymin)/(ymax-ymin))*(d.height-40))-20;					page.setColor(Color.red);					page.drawLine(xhat1,yhat1,xhat2,yhat2);				}				if (MC<niter)				{					for (int count = frame+1; count <= length-1; count++)					{						x1 = (int)(((path[0][count-1]-xmin)/(xmax-xmin))*(d.width-70))+50;						x3 = (int)(((path[0][count]-xmin)/(xmax-xmin))*(d.width-70))+50;						y1 = d.height - (int)(((path[1][count-1]-ymin)/(ymax-ymin))*(d.height-40))-20;						y3 = d.height - (int)(((path[1][count]-ymin)/(ymax-ymin))*(d.height-40))-20;						page.setColor(Color.black);						page.drawLine(x1,y1,x3,y3);					}				}			}			if(animating)			{				jetX = x2-jetWidth/2;				jetY = y2-jetHeight/2;			}			else			{				jetX = (int)((jetXmeter - xmin)/(xmax-xmin)*(d.width-70)+50-jetWidth/2);				jetY = d.height - (int)((jetYmeter-ymin)/(ymax-ymin)*(d.height-40))-20-jetHeight/2;			}			if(cp.showPlane.isSelected())			 	page.drawImage(jet,jetX, jetY,jetWidth,jetHeight,null,null);			page.setColor(Color.black);			page.drawLine(48,d.height-20,d.width-5,d.height-20);			page.drawString(Integer.toString((int)ymin),2,d.height-17);			page.drawLine(50,5,50,d.height-18);			page.drawString(Integer.toString((int)xmin),35,d.height-5);			page.drawLine(d.width-20,d.height-22,d.width-20,d.height-18);			page.drawString(Integer.toString((int)xmax),d.width-35,d.height-5);			page.drawLine(48,20,52,20);			page.drawString(Integer.toString((int)ymax),2,25);		}	}	private class EPanel extends JPanel	{		public double error[];		public double maxerror;		public double avgerror;		public EPanel()		{			error=new double[length];		}		public void paintComponent(Graphics page)		{			super.paintComponent(page);			setBackground(Color.white);			Dimension d = new Dimension(getWidth(), getHeight());			page.clearRect(0,0,d.width,d.height);			maxerror=0;			avgerror=0;			if(ploterror)			{				for(int i=0; i<length; i++)				{					maxerror=Math.max(maxerror,error[i]);					avgerror = avgerror + error[i];				}				for(int i=1; i<length; i++)				{					int x1 = (int)(((float)(i-1.0)/(length-1.0))*(d.width-20))+10;					int x2 = (int)(((float)(i*1.0)/(length-1.0))*(d.width-20))+10;					int y1 = d.height - (int)(((error[i-1])/(maxerror))*(d.height-10));					int y2 = d.height - (int)(((error[i])/(maxerror))*(d.height-10));					page.setColor(Color.red);					page.drawLine(x1,y1,x2,y2);					page.setColor(Color.black);					page.drawLine(x1,d.height,x1,d.height-4);					page.drawLine(x2,d.height,x2,d.height-4);				}				page.drawString(Integer.toString((int)maxerror),2,16);				page.drawString("Avg.: "+Integer.toString((int)avgerror/length),120,16);			}		}	}	private class CheckPanel extends JPanel	{		public JCheckBox showPlane;		public JCheckBox showOrg;		public JCheckBox showRes;		private JLabel checkLabel;		private JLabel pauseLabel;		public JCheckBox pauseBox;		private JSeparator divLine, divLine2;		public JButton resumeButton;		public JCheckBox resBox;		public CheckPanel()		{			setBackground(Color.lightGray);			setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));			checkLabel = new JLabel("Display:");			pauseLabel = new JLabel("Pause between MC steps");			showPlane = new JCheckBox("Plane", true);			showOrg = new JCheckBox("Particles", true);			showRes = new JCheckBox("Resampled particles", true);			pauseBox = new JCheckBox("Enable", false);			resumeButton = new JButton("Resume");			resBox = new JCheckBox("Use Resampling", true);			showPlane.setBackground(Color.lightGray);			showOrg.setBackground(Color.lightGray);			showRes.setBackground(Color.lightGray);			pauseBox.setBackground(Color.lightGray);			resBox.setBackground(Color.lightGray);			divLine = new JSeparator();			divLine2 = new JSeparator();/*			showPlane.setToolTipText("Check here to show the plane in the plot.");			showOrg.setToolTipText("Check here to display the particles before resampling during animation.");			showRes.setToolTipText("Check here to display the resampled particles during animation.");			pauseBox.setToolTipText("Check here to pause animation between Monte Carlo Iterations.");			resumeButton.setToolTipText("Click here to resume animation when paused.");			resBox.setToolTipText("Check here to use resampling when tracking.");*/			showPlane.addMouseListener(new planemouse());			showOrg.addMouseListener(new orgmouse());			showRes.addMouseListener(new resmouse());			pauseBox.addMouseListener(new boxmouse());			resumeButton.addMouseListener(new resumemouse());			resBox.addMouseListener(new resboxmouse());			setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));			add(checkLabel);			add(showPlane);			add(showOrg);			add(showRes);			add(divLine);			add(pauseLabel);			add(pauseBox);			add(resumeButton);			add(divLine2);			add(resBox);			showPlane.addActionListener(new addListener());			resumeButton.addActionListener(new resumeListener());		}	private class planemouse implements MouseListener	{			public void mousePressed(MouseEvent e) {}			public void mouseReleased(MouseEvent e) {}			public void mouseClicked(MouseEvent e) {}			public void mouseEntered(MouseEvent e)			{				helpinfo.setText("Check here to show the plane in the plot.");			}			public void mouseExited(MouseEvent e) {}	}		private class orgmouse implements MouseListener		{				public void mousePressed(MouseEvent e) {}				public void mouseReleased(MouseEvent e) {}				public void mouseClicked(MouseEvent e) {}				public void mouseEntered(MouseEvent e)				{					helpinfo.setText("Check here to display the particles before resampling during animation.");				}				public void mouseExited(MouseEvent e) {}	}	private class resmouse implements MouseListener	{			public void mousePressed(MouseEvent e) {}			public void mouseReleased(MouseEvent e) {}			public void mouseClicked(MouseEvent e) {}			public void mouseEntered(MouseEvent e)			{				helpinfo.setText("Check here to display the resampled particles during animation.");			}			public void mouseExited(MouseEvent e) {}	}	private class boxmouse implements MouseListener	{			public void mousePressed(MouseEvent e) {}			public void mouseReleased(MouseEvent e) {}			public void mouseClicked(MouseEvent e) {}			public void mouseEntered(MouseEvent e)			{				helpinfo.setText("Check here to pause animation between Monte Carlo Iterations.");			}			public void mouseExited(MouseEvent e) {}	}	private class resumemouse implements MouseListener	{			public void mousePressed(MouseEvent e) {}			public void mouseReleased(MouseEvent e) {}			public void mouseClicked(MouseEvent e) {}			public void mouseEntered(MouseEvent e)			{				helpinfo.setText("Click here to resume animation when paused.");			}			public void mouseExited(MouseEvent e) {}	}	private class resboxmouse implements MouseListener	{			public void mousePressed(MouseEvent e) {}			public void mouseReleased(MouseEvent e) {}			public void mouseClicked(MouseEvent e) {}			public void mouseEntered(MouseEvent e)			{				helpinfo.setText("Check here to use resampling when tracking.");			}			public void mouseExited(MouseEvent e) {}	}		private class addListener implements ActionListener		{			public void actionPerformed(ActionEvent event)			{				if(animating)					return;				rp.repaint();			}		}		private class resumeListener implements ActionListener		{			public void actionPerformed(ActionEvent eve)			{				if(paused)				{					xhat[0][0]=0;					xhat[1][0]=0;					xhat[2][0]=0;					xhat[3][0]=0;					for (int i=0; i<numParts; i++)					{						parts.xPosition[i]=jetXmeter+100*generator.nextGaussian();						parts.yPosition[i]=jetYmeter+100*generator.nextGaussian();						parts.xVelocity[i]=xvelocity+7.07107*generator.nextGaussian();						parts.yVelocity[i]=yvelocity+7.07107*generator.nextGaussian();						xhat[0][0]=xhat[0][0]+parts.xPosition[i];						xhat[1][0]=xhat[1][0]+parts.yPosition[i];						xhat[2][0]=xhat[2][0]+parts.xVelocity[i];						xhat[3][0]=xhat[3][0]+parts.yVelocity[i];					}					xhat[0][0]=xhat[0][0]/numParts;					xhat[1][0]=xhat[1][0]/numParts;					xhat[2][0]=xhat[2][0]/numParts;					xhat[3][0]=xhat[3][0]/numParts;					sensorXmeter = Double.parseDouble(lp.Xsensor.getText());					sensorYmeter = Double.parseDouble(lp.Ysensor.getText());					numParts = Integer.parseInt(lp.Npart.getText());					xmax = Math.max(xmax, sensorXmeter);					xmin = Math.min(xmin, sensorXmeter);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -